ai/ios-skills/ios-axiom-concurrency-profiling/SKILL.md
Use when profiling async/await performance, diagnosing actor contention, or investigating thread pool exhaustion. Covers Swift Concurrency Instruments template, task visualization, actor contention analysis, thread pool debugging.
npx skillsauth add kurko/dotfiles axiom-concurrency-profilingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Profile and optimize Swift async/await code using Instruments.
✅ Use when:
❌ Don't use when:
| Track | Information | |-------|-------------| | Swift Tasks | Task lifetimes, parent-child relationships | | Swift Actors | Actor access, contention visualization | | Thread States | Blocked vs running vs suspended |
Symptom: UI freezes, main thread timeline full
Solution patterns:
// ❌ Heavy work on MainActor
@MainActor
class ViewModel: ObservableObject {
func process() {
let result = heavyComputation() // Blocks UI
self.data = result
}
}
// ✅ Offload heavy work
@MainActor
class ViewModel: ObservableObject {
func process() async {
let result = await Task.detached {
heavyComputation()
}.value
self.data = result
}
}
Symptom: Tasks serializing unexpectedly, parallel work running sequentially
Solution patterns:
// ❌ All work serialized through actor
actor DataProcessor {
func process(_ data: Data) -> Result {
heavyProcessing(data) // All callers wait
}
}
// ✅ Mark heavy work as nonisolated
actor DataProcessor {
nonisolated func process(_ data: Data) -> Result {
heavyProcessing(data) // Runs in parallel
}
func storeResult(_ result: Result) {
// Only actor state access serialized
}
}
More fixes:
Symptom: Tasks queued but not executing, gaps in task execution
Cause: Blocking calls exhaust cooperative pool
Common culprits:
// ❌ Blocks cooperative thread
Task {
semaphore.wait() // NEVER do this
// ...
semaphore.signal()
}
// ❌ Synchronous file I/O in async context
Task {
let data = Data(contentsOf: fileURL) // Blocks
}
// ✅ Use async APIs
Task {
let (data, _) = try await URLSession.shared.data(from: fileURL)
}
Debug flag:
SWIFT_CONCURRENCY_COOPERATIVE_THREAD_BOUNDS=1
Detects unsafe blocking in async context.
Symptom: High-priority task waits for low-priority
// ✅ Explicit priority for critical work
Task(priority: .userInitiated) {
await criticalUIUpdate()
}
Swift uses a cooperative thread pool matching CPU core count:
| Aspect | GCD | Swift Concurrency | |--------|-----|-------------------| | Threads | Grows unbounded | Fixed to core count | | Blocking | Creates new threads | Suspends, frees thread | | Dependencies | Hidden | Runtime-tracked | | Context switch | Full kernel switch | Lightweight continuation |
Why blocking is catastrophic:
Run these checks first:
Is work actually async?
await)Holding locks across await?
// ❌ Deadlock risk
mutex.withLock {
await something() // Never!
}
Tasks in tight loops?
// ❌ Overhead may exceed benefit
for item in items {
Task { process(item) }
}
// ✅ Structured concurrency
await withTaskGroup(of: Void.self) { group in
for item in items {
group.addTask { process(item) }
}
}
DispatchSemaphore in async context?
withCheckedContinuation instead| Issue | Symptom in Instruments | Fix |
|-------|------------------------|-----|
| MainActor overload | Long blue bars on main | Task.detached, nonisolated |
| Actor contention | High red:blue ratio | Split actors, use nonisolated |
| Thread exhaustion | Gaps in all threads | Remove blocking calls |
| Priority inversion | High-pri waits for low-pri | Check task priorities |
| Too many tasks | Task creation overhead | Use task groups |
Safe with cooperative pool:
await, actors, task groupsos_unfair_lock, NSLock (short critical sections)Mutex (iOS 18+)Unsafe (violate forward progress):
DispatchSemaphore.wait()pthread_cond_waitThread.sleep() in TaskWWDC: 2022-110350, 2021-10254
Docs: /xcode/improving-app-responsiveness
Skills: axiom-swift-concurrency, axiom-performance-profiling, axiom-synchronization, axiom-lldb (interactive thread state inspection)
data-ai
Merge the current worktree branch into main and sync main back. Use when the user says "merge to main", "ship it", "merge and continue", or after completing a task in a worktree and wanting to continue with the next one.
tools
Synchronize AI agent skills, commands, configs, permissions, hooks, and instructions across Claude Code, Codex CLI, and other Agent Skills-compatible tools. Use when the user asks to pull skills from Claude into Codex, sync Codex work back to Claude, migrate agent commands, reconcile frontmatter, update permissions, or keep agent setup files in parity.
testing
Write or update UI-independent use cases for QA. Use when the user says "write use cases", "add use cases", "QA use cases", "update use cases", "compose use cases", or when starting implementation of a new feature (after plan approval). Also activates for "what should we test", "regression cases", or "use cases for QA".
documentation
Skill on how to write a task. Use when user asks you to write a task (for Asana, Linear, Jira, Notion and equivalent). Also activates when user says "create task", "write task", or similar task creation workflow requests.