Advanced Swift Concurrency: Atomics vs Mutex vs Actors
I tested whether Atomic operations are all they’re cracked up to be by benchmarking its various forms of synchronisation against Actors and Mutex when concurrently counting to 10 million.
Performance between Actors and Atomics were pretty close . The real standout here was Mutex blowing the other two approaches out of the water, counting to 10m in less than half the time of the others.
What you should take away from this is that you shouldn’t immediately reach for sequentially-consistent Atomics as a shiny new panacea to make your synchronisation code run 2 milliseconds faster than an actor otherwise might — unless you have a clear use case, the higher-level tools are usually fine.