Posts for Tag: reduce

Swift AsyncSequence Performance Experimentation

[UPDATE 16/8/2021: Xcode/iOS beta 5 seems to make a massive jump in performance. I'll blog again when I get round to it but wow. From first glance async appending byte by byte appears to be only 3x slower than sync call to load data and the XOR tests are actually faster now in my initial testing.

Updated conclusion - If you can drop iOS 14 support then there is no performance reason not to use AsyncSequence type operations on files and lots of positive reasons to use it.]

At WWDC 2021 amongst the other async talks there was the Meet AsyncSequence talk which amongst other things demonstrated new APIs for getting async sequences of bytes from files or URLs. I was curious as to how they would perform so I did a few tests. Note that the FileHandle and URL bytes properties do not seem to be working in Xcode 13 beta 1 but the version on URLSession does seem to work and can be used for files - see the updates on my last post 

This is a very first pass with some rough numbers to get a feel for rough ballpark feeling. This is iOS 15 beta 1 (on iPhone XS) and Xcode 13 beta 1. Testing was done with -O (speed) optimisation setting. The tests themselves will be at the end of this post. I configured the tests to run just the once because first run performance was consistently slower and I thought therefore more representative of file reading where the file is not already loaded.

As a baseline I included a pure synchronous read into a Data object. The AsyncSequence approach should not get close to the performance of this as it has to do a great deal more context switching at least function calls whereas that is straight-line on a single thread code.

Results