What's new for async-await?

Generated on 8/5/2024

1 search

What's New for Async-Await?

At WWDC 2024, several sessions discussed updates and improvements to async-await in Swift. Here are the key points:

  1. Concurrency Model Enhancements:

    • Swift 6 introduces data race safety, which diagnoses data races at compile time. This is a significant improvement for concurrent programming, ensuring safer and more reliable code. This feature is part of the new Swift 6 language mode, which is opt-in (Platforms State of the Union).
  2. Async Function Implementation:

    • Async functions in Swift are implemented by splitting them into multiple partial functions at runtime. This allows the functions to manage their local state on a separate stack from the C stack, improving performance and memory management (Explore Swift performance).
  3. Memory Allocation for Async Functions:

    • Async tasks hold onto one or more slabs of memory, and when an async function needs to allocate memory, it asks the task for memory from the current slab. If the slab is full, a new slab is allocated. This method is typically faster than traditional malloc, providing a performance profile similar to synchronous functions but with slightly higher overhead (Explore Swift performance).
  4. Testing with Async-Await:

    • Swift testing now supports parallel testing by default, and async-await can be used in test code just as in production code. This allows tests to run more efficiently by suspending and yielding the CPU to other tasks while waiting for asynchronous conditions (Go further with Swift Testing).
  5. Structured Concurrency:

    • Swift's concurrency model, including async-await, structured concurrency, and actors, has been progressively refined. These features collectively contribute to the new data race safety in Swift 6, making concurrent programming easier and safer (What’s new in Swift).

Relevant Sessions

These sessions provide a comprehensive overview of the latest advancements in async-await and concurrency in Swift.

Explore Swift performance

Explore Swift performance

Discover how Swift balances abstraction and performance. Learn what elements of performance to consider and how the Swift optimizer affects them. Explore the different features of Swift and how they’re implemented to further understand the tradeoffs available that can impact performance.

What’s new in Swift

What’s new in Swift

Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.

Go further with Swift Testing

Go further with Swift Testing

Learn how to write a sweet set of (test) suites using Swift Testing’s baked-in features. Discover how to take the building blocks further and use them to help expand tests to cover more scenarios, organize your tests across different suites, and optimize your tests to run in parallel.

Platforms State of the Union

Platforms State of the Union

Discover the newest advancements on Apple platforms.

A Swift Tour: Explore Swift’s features and design

A Swift Tour: Explore Swift’s features and design

Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.