When to use @concuurent?

Asked on 06/11/2025

1 search

The @concurrent attribute in Swift is used to ensure that a function always runs on the concurrent thread pool, freeing up the actor to run other tasks at the same time. This is particularly useful when you want to offload work to the background to improve performance, such as when performing CPU-intensive tasks that should not block the main actor or any other actor.

In the session Embracing Swift concurrency, it is mentioned that using @concurrent isn't always the best choice for APIs, especially when decoding small amounts of data, which is okay to do on the main thread. For libraries, it's often better to provide a non-isolated API and let clients decide whether to offload work.

The session What’s new in Swift also discusses how @concurrent works with the concurrent thread pool to make concurrency more approachable, allowing you to start by writing code that runs on the main actor by default and then offload specific code to the background to run in parallel when ready to embrace concurrency for performance improvements.