Concurrency Profiling — Instruments Workflows
Purpose: Profile and optimize Swift async/await code using Instruments Xcode Version: Xcode 14+ (Swift Concurrency template) iOS Version: iOS 13+
When to Use This Skill
✅ Use this skill when:
- UI stutters during async operations
- Suspecting actor contention
- Tasks queued but not executing
- Main thread blocked during async work
- Need to visualize task execution flow
❌ Do NOT use this skill for:
- Pure CPU performance (use Time Profiler)
- Memory issues unrelated to concurrency (use Allocations)
- Haven't confirmed concurrency is the bottleneck
Swift Concurrency Template
What It Shows
| Track | Information |
|---|---|
| Swift Tasks | Task lifetimes, parent-child relationships |
| Swift Actors | Actor access, contention visualization |
| Thread States | Blocked vs running vs suspended |
Color Coding
- Blue: Task executing
- Red: Task waiting (contention)
- Gray: Task suspended (awaiting)
Key Workflows
Workflow 1: Main Thread Blocking
Symptom: UI freezes, main thread timeline full
- Profile with Swift Concurrency template
- Look at main thread → "Swift Tasks" lane
- Find long blue bars (task executing on main)
- Offload with
Task.detachedornonisolated
Workflow 2: Actor Contention
Symptom: Tasks serializing unexpectedly
- Enable "Swift Actors" instrument
- High red:blue ratio = contention problem
- Fix: Split actors, use
nonisolated, or Mutex for hot paths
Workflow 3: Thread Pool Exhaustion
Symptom: Tasks queued but not executing
Cause: Blocking calls (semaphore.wait(), sync I/O) exhaust cooperative pool
Debug flag:
SWIFT_CONCURRENCY_COOPERATIVE_THREAD_BOUNDS=1Related Skills
- Swift Concurrency — Concurrency patterns
- Synchronization — Mutex vs actor decisions
- Performance Profiling — General profiling