Menu

Cap the Concurrency: TaskGroup and a Fixed Worker Limit for Batch Image Exports in Swift
πŸ“°

Cap the Concurrency: TaskGroup and a Fixed Worker Limit for Batch Image Exports in Swift

DEV Community: swiftΒ·MaxwellΒ·about 7 hours ago
#D5W7EmW8
#devtoswift#devto#dev#group#memory
Long article (1483 words) β€” no AI summary yet.
Reading 0:00
15s threshold

When you export 80 photos, the tempting Swift Concurrency move is to throw every photo into a TaskGroup and let the system sort it out. It reads cleanly. It also tends to decode too many full-size images at once, and on an iPhone that is how a batch that was fine at ten photos starts getting jetsam'd at eighty.

I build BatchMark , an iPhone app for finishing photos in batches, so this is a problem I have to take seriously. What follows is a teaching version of a simple pattern: keep a TaskGroup , but only let a small number of photos be in flight at a time. It is not the app's source.

The problem isn't the group. It's the queue length.

withTaskGroup is a good tool. It gives you structured concurrency, cancellation that actually reaches the children, and a place to collect results.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.