// shelf 2024
Swift Concurrency by Example
Paul Hudson
2 highlights read dec 2024 find this book ↗
Passages
in reading order
-
loc. 383
The important thing to understand here is that Swift cannot tell at compile time whether an await call will suspend or not, and so the same (slightly) more expensive calling convention is used regardless of what actually takes place at runtime.
-
loc. 387
What happens at runtime depends on whether the call suspends or not: If a suspension happens, then Swift will pause the function and all its callers, which has a small performance cost. These will then be resumed later, and ultimately whatever performance cost you pay for the suspension is like a rounding error compared to the performance gain provided by async/await even existing. If a suspension does not happen, no pause will take place and your function will continue to run with the same efficiency and timings as a synchronous function. That last part carries an important side effect: using await will not cause your code to wait for one runloop to go by before continuing.
Every passage I highlighted, up to 1,000 words per book.