WWDC 2017
- Modernizing GCD Usage, How to stay on core - Wednesday
Session video and resources: https://developer.apple.com/videos/play/wwdc2017/706/
- Leverage existing system frameworks
- Express explicit parallelism with
DispatchQueue.concurrentPerform
- Use case: UI & Networking & Database at the same time
- Repeatedly bouncing between contexts like network and database can become expensive. Reasons could be,
- Repeatedly waiting for exclusive access to contented resources
- Fair Locks: Gives a chance to every thread to run in sequence
- Unfair Locks: Reserves thread to finish
- Lock ownership helps resolve priority inversion
- Repeatedly waiting for exclusive access to contented resources
- Single owners, no owners, multiple owners
- Mutex
- FIFO
- Concurrent atomic enqueue
- Serial queues and sources can form a tree
- priority inversion resolves waiting problems according to importance. E.g User initiated task will always come first eventhough it is queued afterwards
- Unified queue identity can block certain threads for priority
- No mutation past activation
- Set the properties of inactive objects before activation
- Source handlers
- Target queues
- Set the properties of inactive objects before activation
- Protecting the Target Queue Hierarchy
- Build your queue hierarchy from bottom to top
- Opt into "static queue hierarchy"
- Not going off core is ever more important
- Size your work appropriately
- Choose good granularity of concurrency
- Modernize your GCD usage