View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vidéos

Ouvrir le menu Fermer le menu
  • Collections
  • Toutes les vidéos
  • À propos

Plus de vidéos

  • À propos
  • Code
  • Swift concurrency: Behind the scenes

    Dive into the details of Swift concurrency and discover how Swift provides greater safety from data races and thread explosion while simultaneously improving performance. We'll explore how Swift tasks differ from Grand Central Dispatch, how the new cooperative threading model works, and how to ensure the best performance for your apps.

    To get the most out of this session, we recommend first watching “Meet async/await in Swift,” “Explore structured concurrency in Swift,” and “Protect mutable state with Swift actors.”

    Ressources

    • The Swift Programming Language: Concurrency
      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    WWDC23

    • Analyze hangs with Instruments
    • Beyond the basics of structured concurrency
    • Swift 的新功能

    WWDC22

    • Eliminate data races using Swift Concurrency
    • Visualize and optimize Swift concurrency

    WWDC21

    • Explore structured concurrency in Swift
    • Meet async/await in Swift
    • Protect mutable state with Swift actors
    • Swift concurrency: Update a sample app
    • What‘s new in Swift

    WWDC17

    • Modernizing Grand Central Dispatch Usage

    WWDC16

    • Concurrent Programming With GCD in Swift 3
  • Rechercher dans cette vidéo…
    • 4:57 - GCD code with hidden performance pitfalls

      func deserializeArticles(from data: Data) throws -> [Article] { /* ... */ }
      func updateDatabase(with articles: [Article], for feed: Feed) { /* ... */ }
      
      let urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: concurrentQueue)
      
      for feed in feedsToUpdate {
          let dataTask = urlSession.dataTask(with: feed.url) { data, response, error in
              // ...
              guard let data = data else { return }
              do {
                  let articles = try deserializeArticles(from: data)
                  databaseQueue.sync {
                      updateDatabase(with: articles, for: feed)
                  }
              } catch { /* ... */ }
          }
          dataTask.resume()
      }
    • 13:18 - Swift concurrency equivalent using a task group

      func deserializeArticles(from data: Data) throws -> [Article] { /* ... */ }
      func updateDatabase(with articles: [Article], for feed: Feed) async { /* ... */ }
      
      await withThrowingTaskGroup(of: [Article].self) { group in
          for feed in feedsToUpdate {
              group.async {
                  let (data, response) = try await URLSession.shared.data(from: feed.url)
                  // ...
                  let articles = try deserializeArticles(from: data)
                  await updateDatabase(with: articles, for: feed)
                  return articles
              }
          }
      }
    • 15:16 - Async functions: stack frames and async frames

      // on Database
      func save(_ newArticles: [Article], for feed: Feed) async throws -> [ID] { /* ... */ }
      
      // on Feed
      func add(_ newArticles: [Article]) async throws {
          let ids = try await database.save(newArticles, for: self)
          for (id, article) in zip(ids, newArticles) {
              articles[id] = article
          }
      }
      
      func updateDatabase(with articles: [Article], for feed: Feed) async throws {
          // skip old articles ...
          try await feed.add(articles)
      }
    • 37:13 - Excessive context switching due to Main actor hoppping

      // on database actor
      func loadArticle(with id: ID) async throws -> Article { /* ... */ }
      
      @MainActor func updateUI(for article: Article) async { /* ... */ }
      
      @MainActor func updateArticles(for ids: [ID]) async throws {
          for id in ids {
              let article = try await database.loadArticle(with: id)
              await updateUI(for: article)
          }
      }
    • 38:18 - Batch UI work to reduce the number of context switches

      // on database actor
      func loadArticles(with ids: [ID]) async throws -> [Article]
      
      @MainActor func updateUI(for articles: [Article]) async
      
      @MainActor func updateArticles(for ids: [ID]) async throws {
          let articles = try await database.loadArticles(with: ids)
          await updateUI(for: articles)
      }

Developer Footer

  • Vidéos
  • WWDC21
  • Swift concurrency: Behind the scenes
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines