•modernizing gcd usage how to stay on core · 2017-06-08 · express explicit parallelism with...

245
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Daniel Chimene, Core Darwin Daniel A. Steffen, Core Darwin Pierre Habouzit, Core Darwin Modernizing GCD Usage How to stay on core Session 706 System Frameworks

Upload: others

Post on 12-Jun-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

#WWDC17

© 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Daniel Chimene, Core Darwin Daniel A. Steffen, Core Darwin Pierre Habouzit, Core Darwin

•Modernizing GCD Usage •How to stay on core • Session 706

System Frameworks

Page 2: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in
Page 3: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

DispatchWorkItem.notify

DispatchQueue.async

DispatchQueue.sync

DispatchQueue.concurrentPerform

DispatchSource.setEventHandler

DispatchSource.activatedispatch_activate

dispatch_sync

dispatch_source_create

dispatch_queue_create

dispatch_applydispatch_once

dispatch_after

dispatch_async

Page 4: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

A8 A10A9A7A6A5A4

Page 5: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Efficiency Through Observation Going off core during an operation reduces efficiency

10µs 500µs 1ms

Efficiency

Observation Time

Page 6: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

faster after combining queue hierarchies

1.3x

Page 7: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Parallelism and concurrency

Page 8: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Parallelism and concurrency•Using GCD for concurrency

Page 9: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Parallelism and concurrency•Using GCD for concurrency•Unified Queue Identity

Page 10: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Parallelism and concurrency•Using GCD for concurrency•Unified Queue Identity•Finding problem spots

Page 11: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Simultaneous execution of closely related computations

Parallelism

ConcurrencyComposition of independently executed tasks

Page 12: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Parallelism

Page 13: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism Simultaneous execution of closely related computations

Page 14: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism Simultaneous execution of closely related computations

Page 15: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism Simultaneous execution of closely related computations

Page 16: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Take Advantage of System Frameworks

Metal 2Accelerate Core ML Core Animation

Page 17: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism with GCD

Express explicit parallelism with DispatchQueue.concurrentPerform

Parallel for-loop—calling thread participates in the computation

More efficient than many asyncs to a concurrent queue

DispatchQueue.concurrentPerform(1000) { i in /* iteration i */ }

Page 18: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism with GCD

Express explicit parallelism with DispatchQueue.concurrentPerform

Parallel for-loop—calling thread participates in the computation

More efficient than many asyncs to a concurrent queue

DispatchQueue.concurrentPerform(1000) { i in /* iteration i */ }

Page 19: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Parallelism with GCD

Express explicit parallelism with DispatchQueue.concurrentPerform

Parallel for-loop—calling thread participates in the computation

More efficient than many asyncs to a concurrent queue

DispatchQueue.concurrentPerform(1000) { i in /* iteration i */ }

NEW

dispatch_apply(DISPATCH_APPLY_AUTO, 1000, ^(size_t i){ /* iteration i */ })

DISPATCH_APPLY_AUTO deploys back to macOS 10.9, iOS 7.0

Page 20: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

{…}

{…}

{…}

DispatchQueue.concurrentPerform(3) { i in /* iteration i */ }

Page 21: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

{…}

{…} {…}

UI Rendering

DispatchQueue.concurrentPerform(3) { i in /* iteration i */ }

Page 22: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

{…}

{…}

Bubble!

{…}

UI Rendering

DispatchQueue.concurrentPerform(3) { i in /* iteration i */ }

Page 23: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

{…}

{…} {…}

{…}

{…}

{…}

UI Rendering

DispatchQueue.concurrentPerform(6) { i in /* iteration i */ }

Page 24: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

{…}

{…} {…}

{…}

{…}

{…}

UI Rendering

DispatchQueue.concurrentPerform(6) { i in /* iteration i */ }

Page 25: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

UI Rendering

DispatchQueue.concurrentPerform(11) { i in /* iteration i */ }

Page 26: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

UI Rendering

DispatchQueue.concurrentPerform(11) { i in /* iteration i */ }

Page 27: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dynamic Resource Availability Choosing an iteration count

UI Rendering

DispatchQueue.concurrentPerform(1000) { i in /* iteration i */ }

Page 28: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Leverage system frameworks

Use DispatchQueue.concurrentPerform

Consider dynamic availability

Parallelism

Page 29: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Concurrency

Page 30: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Composition of independently executed tasks

Page 31: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Composition of independently executed tasks

Page 32: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Composition of independently executed tasks

DatabaseNetworking

User Interface

Page 33: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Composition of independently executed tasks

DatabaseNetworking

User Interface

Page 34: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

User Interface

Concurrency Composition of independently executed tasks

Page 35: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

User Interface

Concurrency Composition of independently executed tasks

Page 36: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

Networking

User Interface

Concurrency Composition of independently executed tasks

Page 37: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

Networking

User Interface

Concurrency Composition of independently executed tasks

Touch!

Page 38: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

Networking

User Interface

Concurrency Composition of independently executed tasks

Touch!

Page 39: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Context switching

User Interface Database Networking

Page 40: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Concurrency Context switching

User Interface Database Networking

System Trace in Depth WWDC 2016

Page 41: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Context Switching The power of concurrency

The OS can choose a new thread at any time

User Interface Database Networking

Page 42: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Context Switching The power of concurrency

The OS can choose a new thread at any time• A higher priority thread needs the CPU

User Interface Database Networking

Page 43: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Context Switching The power of concurrency

The OS can choose a new thread at any time• A higher priority thread needs the CPU• A thread finishes its current work

User Interface Database Networking

Page 44: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Context Switching The power of concurrency

The OS can choose a new thread at any time• A higher priority thread needs the CPU• A thread finishes its current work• Waiting to acquire a resource

User Interface Database Networking

Page 45: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Context Switching The power of concurrency

The OS can choose a new thread at any time• A higher priority thread needs the CPU• A thread finishes its current work• Waiting to acquire a resource• Waiting for an asynchronous request to complete

User Interface Database Networking

Page 46: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive

Page 47: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive

Page 48: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive• CPU runs less efficiently

Page 49: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive• CPU runs less efficiently

Page 50: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive • CPU runs less efficiently • There may be others ahead in line for CPU access

Page 51: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive • CPU runs less efficiently • There may be others ahead in line for CPU access

Page 52: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly bouncing between contexts can become expensive • CPU runs less efficiently • There may be others ahead in line for CPU access

Page 53: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 54: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Excessive Context Switching Too much of a good thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 55: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Too much of a good thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 56: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention

Page 57: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Visualization in Instruments

Page 58: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Visualization in Instruments

Page 59: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Visualization in Instruments

10µs 10µs

Page 60: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Visualization in Instruments

Frequent context-switching

10µs 10µs

Page 61: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention

Page 62: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention

Page 63: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Fair locks

owned

Lock Contention Fair locks

Page 64: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Fair locks

owned reserved

Lock Contention Fair locks

Page 65: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Fair locks

owned reserved

Lock Contention Fair locks

Page 66: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Fair locks

owned reserved owned

Lock Contention Fair locks

Page 67: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

owned reserved owned

Fair locksLock Contention

Page 68: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Unfair locks

owned

Page 69: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Unfair locks

owned waiters

Page 70: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Unfair locks

owned ownedwaiters

Page 71: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Contention Use the right lock for the job

Unfair Fair

Available types os_unfair_lockpthread_mutex_t, NSLock DispatchQueue.sync

Contended lock re-acquisition Can steal the lock Context switches to next waiter

Subject to waiter starvation Yes No

Page 72: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Ownership

owned ownedwaiters

Page 73: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Ownership

Ownership helps resolve priority inversion • High priority waiter • Low priority owner

owned ownedwaiters

Page 74: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Ownership

Single Owner

Serial queues

DispatchWorkItem.wait

os_unfair_lock

pthread_mutex, NSLock

Page 75: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Ownership

Single Owner

Serial queues

DispatchWorkItem.wait

os_unfair_lock

pthread_mutex, NSLock

No Owner

dispatch_semaphore

dispatch_group

pthread_cond, NSCondition

Queue suspension

Page 76: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Lock Ownership

Single Owner

Serial queues

DispatchWorkItem.wait

os_unfair_lock

pthread_mutex, NSLock

No Owner

dispatch_semaphore

dispatch_group

pthread_cond, NSCondition

Queue suspension

Multiple Owners

Private concurrent queues

pthread_rwlock

Page 77: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Optimizing Lock Contention

Inefficient behaviors are often emergent properties

Visualize your app’s behavior with Instruments

Use the right lock for the job

Page 78: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Too Much of a Good Thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 79: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Daniel A. Steffen, Core Darwin

•Using GCD for Concurrency

Page 80: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Grand Central Dispatch

Simplifying iPhone App Development with Grand Central Dispatch WWDC 2010

Asynchronous Design Patterns with Blocks, GCD, and XPC WWDC 2012

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Building Responsive and Efficient Apps with GCD WWDC 2015

Concurrent Programming with GCD in Swift 3 WWDC 2016

Page 81: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Serial Dispatch Queue

Fundamental GCD primitive

Page 82: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Serial Dispatch Queue

Fundamental GCD primitive• Mutual exclusion• FIFO ordered

Page 83: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Serial Dispatch Queue

Fundamental GCD primitive• Mutual exclusion• FIFO ordered• Concurrent atomic enqueue• Single dequeuer

Page 84: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

Serial Dispatch Queue

Page 85: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

queue

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

Serial Dispatch Queue

Page 86: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

queue

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

queue.async { 2 }

2

queue.async { 1 }

1

Serial Dispatch Queue

Page 87: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

queue

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

2

queue.sync { 3 }

1 3

Serial Dispatch Queue

Page 88: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

queue

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

queue.sync { 3 }

3

Serial Dispatch Queue

Page 89: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

queue

let queue = DispatchQueue(label: "com.example.queue") queue.async { /* 1 */ } queue.async { /* 2 */ } queue.sync { /* 3 */ }

queue.sync { 3 }3

Serial Dispatch Queue

Page 90: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dispatch Source

Event monitoring primitive

let source = DispatchSource.makeReadSource(fileDescriptor: fd, queue: queue) source.setEventHandler { read(fd) } source.setCancelHandler { close(fd) } source.activate()

Page 91: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dispatch Source

Event monitoring primitive

let source = DispatchSource.makeReadSource(fileDescriptor: fd, queue: queue) source.setEventHandler { read(fd) } source.setCancelHandler { close(fd) } source.activate()

Page 92: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dispatch Source

Event monitoring primitive• Event handler executes on target queue

let source = DispatchSource.makeReadSource(fileDescriptor: fd, queue: queue) source.setEventHandler { read(fd) } source.setCancelHandler { close(fd) } source.activate()

Page 93: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dispatch Source

Event monitoring primitive• Event handler executes on target queue• Invalidation pattern with explicit cancellation

let source = DispatchSource.makeReadSource(fileDescriptor: fd, queue: queue) source.setEventHandler { read(fd) } source.setCancelHandler { close(fd) } source.activate()

Page 94: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Dispatch Source

Event monitoring primitive• Event handler executes on target queue• Invalidation pattern with explicit cancellation• Initial setup followed by activate

let source = DispatchSource.makeReadSource(fileDescriptor: fd, queue: queue) source.setEventHandler { read(fd) } source.setCancelHandler { close(fd) } source.activate()

Page 95: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Target Queue Hierarchy

Serial queues and sources can form a tree

Page 96: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Target Queue Hierarchy

Serial queues and sources can form a tree S1 S2

Q1 Q2

Page 97: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Target Queue Hierarchy

Serial queues and sources can form a tree S1 S2

EQ

Q1 Q2

let Q1 = DispatchQueue(label: "Q1", target: EQ ) let Q2 = DispatchQueue(label: "Q2", target: EQ )

Page 98: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Target Queue Hierarchy

Serial queues and sources can form a tree

Shared single mutual exclusion context

Independent individual queue order

S1 S2

EQ

Q1 Q2

let Q1 = DispatchQueue(label: "Q1", target: EQ ) let Q2 = DispatchQueue(label: "Q2", target: EQ )

Page 99: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

Target Queue Hierarchy

Page 100: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

Target Queue Hierarchy

Q1

Q2

1 2 3 4 5 6

A B C D

Page 101: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

Target Queue Hierarchy

Q1

Q2

EQ1 2 3 4 5 6A B C D

Page 102: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

Target Queue Hierarchy

Q1

Q2

EQ1 2 3 4 5 6A B C D

Page 103: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Quality of Service

Abstract notion of priority

Provides explicit classification of your work

Affects various execution properties

User Interactive

User Initiated

Utility

Background

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Page 104: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Quality of Service

Abstract notion of priority

Provides explicit classification of your work

Affects various execution properties

User Interactive

User Initiated

Utility

Background

UI

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Page 105: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Quality of Service

Abstract notion of priority

Provides explicit classification of your work

Affects various execution properties

User Interactive

User Initiated

Utility

Background

UI

IN

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Page 106: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Quality of Service

Abstract notion of priority

Provides explicit classification of your work

Affects various execution properties

User Interactive

User Initiated

Utility

Background

UI

IN

UT

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Page 107: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Quality of Service

Abstract notion of priority

Provides explicit classification of your work

Affects various execution properties

User Interactive

User Initiated

Utility

Background

UI

IN

UT

BG

Power, Performance, and Diagnostics: What's new in GCD and XPC WWDC 2014

Page 108: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

UI

IN

UT

BG

S1 S2

EQ

Q1 Q2

S1

QoS and Target Queue Hierarchy

Page 109: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

UI

IN

UT

BG

S1 S2

EQ

Q1 Q2

S1

QoS and Target Queue Hierarchy

UI

Page 110: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

UI

IN

UT

BG

S1 S2

EQ

Q1 Q2

S1

QoS and Target Queue Hierarchy

UI

UT

Page 111: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

UI

IN

UT

BG

S1 S2

EQ

Q1 Q2

S1S1

QoS and Target Queue Hierarchy

UI

UT

Page 112: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1S1

EQ

QoS and Target Queue Hierarchy

UI

UT

Page 113: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

UI

UT

Page 114: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

IN

queue.async { … }

UI

UT

Page 115: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

IN

queue.async { … }

UI

UT

Page 116: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

IN

queue.async { … }

UI

UT

Page 117: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

UI

UT

Priority Inversion

Page 118: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S1 S2

EQ

Q1 Q2

S1

EQ

QoS and Target Queue Hierarchy

UI

UI

UT

Priority Inversion Resolved

Page 119: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Granularity of Concurrency

Page 120: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

User Interface

Networking

Page 121: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Database

User Interface

Networking

Page 122: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Monitoring Setup

Page 123: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Monitoring Setup

Network Connection

Page 124: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Monitoring Setup

S

Q

Network Connection

Dispatch Source

Dispatch Queue

Page 125: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Monitoring Setup

S

Q

Page 126: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Monitoring Setup

S

Q

S

Q

S

Q

S

Q

S

Q

S

Q

S

Q

Page 127: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Handling on Many Independent Queues

S

Q

S

Q

S

Q

Page 128: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Handling on Many Independent Queues

Q

S

Q

S

Q

S

Q

Page 129: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Handling on Many Independent Queues

Q

Q

Q

S

Q

S

Q

S

Q

Page 130: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Handling on Many Independent Queues

Q

Q

Q

S

Q

S

Q

S

Q

Page 131: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Event Handling on Many Independent Queues

Q

Q

Q

S

Q

S

Q

S

Q

Page 132: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Single Mutual Exclusion Context

S

Q

S

Q

S

Q

Page 133: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Single Mutual Exclusion Context

EQ

S

Q

S

Q

S

Q

Page 134: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Single Mutual Exclusion Context

Q

Q

Q

EQ

S

Q

S

Q

S

Q

Page 135: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Single Mutual Exclusion Context

Q

Q

Q

EQ

S

Q

S

Q

S

Q

EQ

Page 136: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Too Much of a Good Thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 137: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Page 138: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Page 139: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Many queues becoming active at once • Independent per-client sources • Independent per-object queues

Page 140: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Many workitems submitted to global concurrent queue

Page 141: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Many workitems submitted to global concurrent queue• If workitems block, more threads will be created • May lead to thread explosion

Page 142: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Avoid Unbounded Concurrency Repeatedly switching between independent operations

Many workitems submitted to global concurrent queue

Building Responsive and Efficient Apps with GCD WWDC 2015

• If workitems block, more threads will be created • May lead to thread explosion

Page 143: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

One Queue per Subsystem

Page 144: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

One Queue per Subsystem

DatabaseNetworking

User Interface

Main Queue

Page 145: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

One Queue per Subsystem

DatabaseNetworking

User Interface

Serial QueueSerial Queue

Main Queue

Page 146: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

One Queue Hierarchy per Subsystem

NQ DQSerial QueueSerial Queue

Main Queue

DatabaseNetworking

User Interface

Page 147: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

One Queue Hierarchy per Subsystem

NQ DQ

Serial QueueSerial Queue

Main Queue

DatabaseNetworking

User Interface

Page 148: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Good Granularity of Concurrency

Fixed number of serial queue hierarchies

Page 149: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Good Granularity of Concurrency

Fixed number of serial queue hierarchies

Page 150: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Good Granularity of Concurrency

Fixed number of serial queue hierarchies

Coarse workitem granularity between hierarchies

Page 151: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Good Granularity of Concurrency

Fixed number of serial queue hierarchies

Coarse workitem granularity between hierarchies

User Interface Database Networking

Page 152: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Good Granularity of Concurrency

Fixed number of serial queue hierarchies

Coarse workitem granularity between hierarchies

Finer workitem granularity inside a hierarchy

User Interface Database

Page 153: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Using GCD for Concurrency

Organize queues and sources into serial queue hierarchies

Use a fixed number of serial queue hierarchies

Size your workitems appropriately

Page 154: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Pierre Habouzit, Core Darwin

•Introducing Unified Queue Identity

Page 155: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Mutual Exclusion Context Deep dive

S1 S2

EQ

Q1 Q2

S1

UI

UT

Page 156: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

S2

UI

Mutual Exclusion Context Deep dive

S1

UT

Page 157: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Unified Queue Identity

let EQ = DispatchQueue(label: "com.example.exclusion-context")

EQ

ApplicationKernel

Page 158: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

EQ.async { … }

Kernel

Unified Queue Identity Asynchronous workitems

Application

Page 159: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

EQ.async { … }

Kernel

Unified Queue Identity Asynchronous workitems

Application

Page 160: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

EQ.async { … }

EQ

Kernel

Unified Queue Identity Asynchronous workitems

Application

NEW

Page 161: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQOwner BG

EQ.async { … }

EQ

Kernel

Unified Queue Identity Asynchronous workitems

Application

NEW

Page 162: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQOwner BG

Unified Queue Identity Asynchronous workitems

Kernel Application

EQ

NEW

Page 163: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQOwner

EQ.async { … }

BG

Unified Queue Identity Asynchronous workitems

Kernel Application

EQ

NEW

Page 164: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQOwner

EQ.async { … }

UT

Unified Queue Identity Asynchronous workitems

Kernel Application

EQ

NEW

Page 165: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQOwner UT

Unified Queue Identity Asynchronous workitems

Kernel Application

EQ

NEW

Page 166: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Owner

Unified Queue Identity Synchronous workitems

EQ

EQ.sync { … }

Kernel

UT

ININ

EQ

Application

NEW

Page 167: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Owner

Unified Queue Identity Synchronous workitems

EQ

EQ.sync { … }

Kernel

UT

ININ

EQ

Application

NEW

Page 168: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Sync Waiters

Owner

Unified Queue Identity Synchronous workitems

EQ

EQ.sync { … }

Kernel

IN

IN

EQ

Application

NEW

Page 169: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Sync Waiters

Owner

Unified Queue Identity Synchronous workitems

EQ

EQ.sync { … }

Kernel

IN

IN

EQ

Application

NEW

Page 170: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

S2

UI

UT

S1

One Identity to Find Them All … and in the kernel bind them

NEW

Page 171: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQUT

S1

let S1 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S1.setEventHandler { … } S1.activate()

Kernel Application

NEWOne Identity to Find Them All … and in the kernel bind them

Page 172: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQUT

S1

let S1 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S1.setEventHandler { … } S1.activate()

Kernel Application

NEWOne Identity to Find Them All … and in the kernel bind them

Page 173: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQUT

S1

let S1 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S1.setEventHandler { … } S1.activate()

Kernel

UT

Application

NEWOne Identity to Find Them All … and in the kernel bind them

Page 174: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQUT

S1

let S1 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S1.setEventHandler { … } S1.activate()

Kernel

Kernel Events

UT

EQ

Application

Sync Waiters

Owner

NEWOne Identity to Find Them All … and in the kernel bind them

Page 175: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

let S2 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S2.setEventHandler(qos: .UserInteractive) { … } S2.activate()

S2

Kernel

Kernel Events

UI

UT

EQ

Application

Sync Waiters

OwnerUT

NEWOne Identity to Find Them All … and in the kernel bind them

Page 176: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

let S2 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S2.setEventHandler(qos: .UserInteractive) { … } S2.activate()

S2

Kernel

Kernel Events

UI

UT

EQ

Application

Sync Waiters

OwnerUT

NEWOne Identity to Find Them All … and in the kernel bind them

Page 177: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

let S2 = DispatchSource.makeReadSource( fileDescriptor: fd, queue: EQ) S2.setEventHandler(qos: .UserInteractive) { … } S2.activate()

S2

Kernel

Kernel Events UI

UT

EQ

Application

Sync Waiters

OwnerUT

NEWOne Identity to Find Them All … and in the kernel bind them

Page 178: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Too Much of a Good Thing

Repeatedly waiting for exclusive access to contended resources

Repeatedly switching between independent operations

Repeatedly bouncing an operation between threads

Page 179: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S2

UI

EQ

UT

S1

Without Unified Identity In macOS Sierra and iOS 10

UT

Page 180: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

S2

S1UT

UI

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 181: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

E1S1

S2

S1UT

UI

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 182: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E1

S2

S1S1UT

UI

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 183: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E1

S2

S1UT

UI

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 184: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E1

S2

S1UT

UI

S1 Handler

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 185: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 HandlerE1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 186: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2S2

S1UT

UI

EQ

S1 HandlerE1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 187: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2S2

S1UT

UI

S1 Handler

EQ

E1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 188: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ

E1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 189: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ

S2 Handler

E2

E1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 190: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ

S2 Handler

EQE2

E1

E1

Without Unified Identity In macOS Sierra and iOS 10

EQ

Page 191: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ EQ

S2 Handler

E2

E1

E1 E2

EQ

Leveraging Ownership and Unified Identity

Page 192: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ EQ

S2 Handler

E2

E1

E1 E2

EQ

Leveraging Ownership and Unified Identity

Page 193: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQ

E2S2

S1UT

UI

S1 Handler

EQ EQ

S2 Handler

E2

E1

E1

EQ

Leveraging Ownership and Unified Identity

Page 194: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQS1 Handler S2 HandlerE1 E2

S2

S1UT

UI

Leveraging Ownership and Unified Identity

EQ

NEW

Page 195: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQS1 Handler S2 HandlerE1 E2

S2

S1UT

UI

Leveraging Ownership and Unified Identity

EQ

NEW

Page 196: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQS1 Handler S2 HandlerE1 E2

S2S2

S1UT

UI

Leveraging Ownership and Unified Identity

EQ

NEW

Page 197: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQS1 Handler S2 HandlerE1 E2

S2S2

S1UT

UI

Leveraging Ownership and Unified Identity

EQ

NEW

Page 198: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

EQS1 Handler S2 HandlerE1 E2

S2S2

S1UT

UI

Leveraging Ownership and Unified Identity

EQ

NEW

Page 199: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

The runtime uses every possible hint to optimize behavior

Page 200: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

•Modernizing Existing Code

Page 201: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Modernizing Existing Code

No dispatch object mutation after activation

Protect your target queue hierarchy

Page 202: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Set the properties of inactive objects before activation • Source handlers • Target queues

No Mutation Past Activation

Page 203: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

let mySource = DispatchSource.makeReadSource(fileDescriptor: fd, queue: myQueue)

Set the properties of inactive objects before activation • Source handlers • Target queues

No Mutation Past Activation

Page 204: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

let mySource = DispatchSource.makeReadSource(fileDescriptor: fd, queue: myQueue)

mySource.setEventHandler(qos: .userInteractive) { … }mySource.setCancelHandler { close(fd) }

Set the properties of inactive objects before activation • Source handlers • Target queues

No Mutation Past Activation

Page 205: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

let mySource = DispatchSource.makeReadSource(fileDescriptor: fd, queue: myQueue)

mySource.setEventHandler(qos: .userInteractive) { … }mySource.setCancelHandler { close(fd) }

mySource.activate()

Set the properties of inactive objects before activation • Source handlers • Target queues

No Mutation Past Activation

Page 206: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

let mySource = DispatchSource.makeReadSource(fileDescriptor: fd, queue: myQueue)

mySource.setEventHandler(qos: .userInteractive) { … }mySource.setCancelHandler { close(fd) }

mySource.activate()

mySource.setTarget(queue: otherQueue)

Set the properties of inactive objects before activation • Source handlers • Target queues

No Mutation Past Activation

Page 207: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Effects of Queue Graph Mutation

Priority and ownership snapshots can become stale • Defeats priority inversion avoidance • Defeats direct handoff optimization • Defeats event delivery optimization

Page 208: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Effects of Queue Graph Mutation

Priority and ownership snapshots can become stale • Defeats priority inversion avoidance • Defeats direct handoff optimization • Defeats event delivery optimization

System frameworks may create sources on your behalf • XPC connections are like sources

Page 209: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Protecting the Target Queue Hierarchy

Page 210: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2

Page 211: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2

Page 212: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Opt into “static queue hierarchy”

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2

Page 213: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Opt into “static queue hierarchy”

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2

Page 214: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Opt into “static queue hierarchy”

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2Q1 = dispatch_queue_create("Q1", DISPATCH_QUEUE_SERIAL) dispatch_set_target_queue(Q1, EQ)

Page 215: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Build your queue hierarchy bottom to top

Opt into “static queue hierarchy”

Protecting the Target Queue Hierarchy

S1 S2

EQ

Q1 Q2Q1 = dispatch_queue_create("Q1", DISPATCH_QUEUE_SERIAL) dispatch_set_target_queue(Q1, EQ)

Q1 = dispatch_queue_create_with_target("Q1", DISPATCH_QUEUE_SERIAL, EQ)

Page 216: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Daniel A. Steffen, Core Darwin

•Demo •Finding problem spots

Page 217: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in
Page 218: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

98

Page 219: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

98

Page 220: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

99

Page 221: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

99

Page 222: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

100

Page 223: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

100

Page 224: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

101

Page 225: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

101

Page 226: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

102

Page 227: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

102

Page 228: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

103

Page 229: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

103

Page 230: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

104

Page 231: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

104

Page 232: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

105

Page 233: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

105

Page 234: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

106

Page 235: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

106

Page 236: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

107

Page 237: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

107

Page 238: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

108

Page 239: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

108

Page 240: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Daniel A. Steffen, Core Darwin

•Demo •Finding problem spots

Page 241: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Summary

Not going off-core is ever more important

Size your work appropriately

Choose good granularity of concurrency

Modernize your GCD usage

Use tools to find problem spots

Page 242: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

More Informationhttps://developer.apple.com/wwdc17/706

Page 243: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Related Sessions

Introducing Core ML WWDC 2017

Accelerate and Sparse Solvers Grand Ballroom A Thursday 10:00AM

Using Metal 2 for Compute Grand Ballroom A Thursday 4:10PM

Writing Energy Efficient Apps Executive Ballroom Friday 9:00AM

App Startup Time: Past, Present, and Future Hall 2 Friday 10:00AM

Page 244: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in

Labs

Kernel & Runtime Lab Technology Lab D Wed 1:50PM–4:10PM

Kernel & Runtime Lab Technology Lab J Thu 10:00AM–12:00PM

Performance Profiling and Runtime Analysis Tools Lab Technology Lab K Thu 1:00PM–4:10PM

Optimizing App Startup Time Lab Technology Lab E Fri 11:00AM–12:30PM

Page 245: •Modernizing GCD Usage How to stay on core · 2017-06-08 · Express explicit parallelism with DispatchQueue.concurrentPerform Parallel for-loop—calling thread participates in