Just wondering if there is an equivalent of DispatchQueue.concurrentPerform()
with the new async/await pattern introduced with Swift 5.5?
I'm using concurrentPerform to iterate through all the pixels of an image and was wondering if this is possible with the new async/await pattern too. Would love to do some comparisons on performance.
Dispatch's concurrentPerform is a parallelism API and Swift 5.5 introduces concurrency not parallelism. (Please refer to this segment of our previous WWDC talk - https://developer.apple.com/videos/play/wwdc2017/706/?time=196 - for definitions of these concepts and how they differ).
There are no parallelism APIs with Swift concurrency that you can use that have the same behaviour of concurrentPerform. One noteworthy distinction is that concurrentPerform in dispatch is not an asynchronous operation - the caller thread participates in the operation and will block until all the operations in the concurrentPerform are completed.
A TaskGroup might feel like a tempting solution but it provides structured concurrency not parallelism. The dispatch equivalent for a TaskGroup would be to queue.async a bunch of work items to a concurrent queue and group the work items together with a DispatchGroup. It does not semantically provide you with the notion that the DispatchGroup is for a parallel compute workload, which is what concurrentPerform does.