Remix.run Logo
astrange 13 hours ago

> The design goal of structured concurrency is to have a safe way of using all available CPU cores on the device/computer.

That's parallelism. Concurrency is mostly about hiding latency from I/O operations like network tasks.

gilgoomesh 12 hours ago | parent [-]

Network operations are "asynchrony". Together with parallelism, they are both kinds of concurrency and Swift concurrency handles both.

Swift's "async let" is parallelism. As are Task groups.

eptcyka 12 hours ago | parent | next [-]

Sure, but as soon as they released their first iteration, they immediately went back to the drawing board and just slapped @MainActor on everything they could because most people really do not care.

ninkendo 11 hours ago | parent | next [-]

Well yes, but that’s because the iOS UI is single threaded, just like every other UI framework under the sun.

It doesn’t mean there isn’t good support for true parallelism in swift concurrency, it’s super useful to model interactions with isolated actors (e.g. the UI thread and the data it owns) as “asynchronous” from the perspective of other tasks… allowing you to spawn off CPU-heavy operations that can still “talk back” to the UI, but they simply have to “await” the calls to the UI actor in case it’s currently executing.

The model works well for both asynchronous tasks (you await the long IO operation, your executor can go back to doing other things) and concurrent processing (you await any synchronization primitives that require mutual exclusivity, etc.)

There’s a lot of gripes I have with swift concurrency but my memory is about 2 years old at this point and I know Swift 6 has changed a lot. Mainly around the complete breakage you get if you ever call ObjC code which is using GCD, and how ridiculously easy it is to shoot yourself in the foot with unsafe concurrency primitives (semaphores, etc) that you don’t even know the code you’re calling is using. But I digress…

jshier 8 hours ago | parent | prev [-]

Not really true; @MainActor was already part of the initial version of Swift Concurrency. That Apple has yet to complete the needed updates to their frameworks to properly mark up everything is a separate issue.

jshier 8 hours ago | parent | prev [-]

async let and TaskGroups are not parallelism, they're concurrency. They're usually parallel because the Swift concurrency runtime allows them to be, but there's no guarantee. If the runtime thread pool is heavily loaded and only one core is available, they will only be concurrent, not parallel.