Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Breaking up with DispatchQueue: Itʼs Not Me, It...

Breaking up with DispatchQueue: Itʼs Not Me, Itʼs Unsafe

In this talk, we’ll explore the common pitfalls of using DispatchQueue and why, despite its power, the Swift compiler can’t always save us from mistakes. As Swift moves toward a compiler-first approach, we’ll see how guarantees are provided earlier in development. I’ll give a brief overview of Swift concurrency, highlighting it's complexities and key pitfalls. Finally, I’ll share how we at Monzo are adopting Swift concurrency, module by module, and building the tools to support this transition.

Oliver Atkinson is a Senior Software Engineer at Monzo with over a decade of experience in software development. He has worked at companies like Sky and Blockchain.com, building mobile apps with a focus on clean, maintainable code. At Monzo, Oliver has been responsible for the new payment experience and adding support for under-16 bank accounts. He is currently working on Monzo’s multiplayer experience, exploring the possibilities of gifting. Additionally, he is helping drive the company’s adoption of Swift concurrency. Oliver is passionate about solving real-world problems and sharing what he has learned along the way.

Leeds Mobile

November 06, 2024
Tweet

More Decks by Leeds Mobile

Other Decks in Technology

Transcript

  1. Leeds Mobile lock - NSLock - NSRecursiveLock - os_unfair_lock -

    OSAllocatedUnfairLock - DispatchSemaphore - …
  2. Leeds Mobile queue Execute code concurrently on multicore hardware by

    submitting work to dispatch queues managed by the system.
  3. Leeds Mobile Swift Concurrency 1 Modern concurrency model 2 Improved

    safety 3 First-class language support 4 Early detection of data races 5 Compile-time safety 6 Simplified “callback hellˮ
  4. Not quite… Swift Concurrency is not easy Leeds Mobile 1

    2 3 4 Timing & Ordering Lack of Caller Control Sendable Actor Reentrancy 5 6 Mental Model async/await … everywhere!
  5. Sendable Capture of 'self' with non-sendable type *' in a

    @Sendable closure. Static property * is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6 Non-sendable type '*' returned by implicitly asynchronous call to global actor '*'-isolated function cannot cross actor boundary Non-sendable type '*' returned by call to actor-isolated function cannot cross actor boundary Passing argument of non-sendable type '*' into actor-isolated context may introduce data races
  6. Leeds Mobile Journey to Swift Concurrency August Our beginnings Forming

    the Working Group Creating a Hub in Notion Create MonzoConcurrency Sessions August September November 22 New Features & Migrate December+
  7. Leeds Mobile Journey to Swift Concurrency August Our beginnings Forming

    the Working Group Creating a Hub in Notion Create MonzoConcurrency Sessions August September November 24 New Features & Migrate December+
  8. * We still deploy to iOS 15 so canʼt yet

    use Clock MonzoConcurrency
  9. Leeds Mobile Journey to Swift Concurrency August Our beginnings Forming

    the Working Group Creating a Hub in Notion Create MonzoConcurrency Sessions August September November 28 New Features & Migrate December+
  10. Migration Leeds Mobile https://www.swift.org/migration/documentation/migrationguide/ 1. Migrate to Xcode 16 &

    Swift 6 Compiler 2. Enable targeted concurrency checking 3. Enable complete checking 4. Enable Swift 6
  11. It may be a learning curve, and a lot of

    effort… You can do it and itʼs worth it!