axiom-ios-concurrency

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

iOS Concurrency Router

iOS 并发路由

You MUST use this skill for ANY concurrency, async/await, threading, or Swift 6 concurrency work.
任何涉及并发、async/await、线程或Swift 6并发的工作,都必须使用此技能。

When to Use

使用场景

Use this router when:
  • Writing async/await code
  • Seeing concurrency errors (data races, actor isolation)
  • Working with @MainActor
  • Dealing with Sendable conformance
  • Optimizing Swift performance
  • Migrating to Swift 6 concurrency
  • App freezes during loading (likely main thread blocking)
在以下场景中使用此路由:
  • 编写async/await代码
  • 遇到并发错误(数据竞争、actor隔离问题)
  • 处理@MainActor相关内容
  • 解决Sendable合规性问题
  • 优化Swift性能
  • 迁移至Swift 6并发模型
  • 应用加载时冻结(大概率是主线程阻塞导致)

Conflict Resolution

冲突解决

ios-concurrency vs ios-performance: When app freezes or feels slow:
  1. Try ios-concurrency FIRST — Main thread blocking is the #1 cause of UI freezes. Check for synchronous work on @MainActor before profiling.
  2. Only use ios-performance if concurrency fixes don't help — Profile after ruling out obvious blocking.
ios-concurrency vs ios-build: When seeing Swift 6 concurrency errors:
  • Use ios-concurrency, NOT ios-build — Concurrency errors are CODE issues, not environment issues
  • ios-build is for "No such module", simulator issues, build failures unrelated to Swift language errors
Rationale: A 2-second freeze during data loading is almost always
await
on main thread or missing background dispatch. Domain knowledge solves this faster than Time Profiler.
ios-concurrency vs ios-performance:当应用出现冻结或运行缓慢时:
  1. 优先尝试ios-concurrency——主线程阻塞是UI冻结的首要原因。在进行性能分析前,先检查@MainActor上的同步操作。
  2. 仅当并发修复无效时,再使用ios-performance——排除明显的阻塞问题后再进行性能分析。
ios-concurrency vs ios-build:当遇到Swift 6并发错误时:
  • 使用ios-concurrency,而非ios-build——并发错误属于代码问题,而非环境问题
  • ios-build适用于“找不到模块”、模拟器问题、与Swift语言错误无关的构建失败等场景
原理:数据加载时出现的2秒冻结,几乎总是主线程上的
await
操作或缺少后台调度导致的。领域知识比时间分析器能更快解决此类问题。

Routing Logic

路由逻辑

Swift Concurrency Issues

Swift并发问题

Swift 6 concurrency patterns
/skill axiom-swift-concurrency
  • async/await patterns
  • @MainActor usage
  • Actor isolation
  • Sendable conformance
  • Data race prevention
  • Swift 6 migration
Swift performance
/skill axiom-swift-performance
  • Value vs reference types
  • Copy-on-write optimization
  • ARC overhead
  • Generic specialization
  • Collection performance
Synchronous actor access
/skill axiom-assume-isolated
  • MainActor.assumeIsolated
  • @preconcurrency protocol conformances
  • Legacy delegate callbacks
  • Testing MainActor code synchronously
Thread-safe primitives
/skill axiom-synchronization
  • Mutex (iOS 18+)
  • OSAllocatedUnfairLock (iOS 16+)
  • Atomic types
  • Lock vs actor decision
Parameter ownership
/skill axiom-ownership-conventions
  • borrowing/consuming modifiers
  • Noncopyable types (~Copyable)
  • ARC traffic reduction
  • consume operator
Concurrency profiling
/skill axiom-concurrency-profiling
  • Swift Concurrency Instruments template
  • Actor contention diagnosis
  • Thread pool exhaustion
  • Task visualization
Swift 6并发模式
/skill axiom-swift-concurrency
  • async/await模式
  • @MainActor使用
  • Actor隔离
  • Sendable合规性
  • 数据竞争预防
  • Swift 6迁移
Swift性能
/skill axiom-swift-performance
  • 值类型与引用类型
  • 写时复制(Copy-on-write)优化
  • ARC开销
  • 泛型特化
  • 集合性能
同步Actor访问
/skill axiom-assume-isolated
  • MainActor.assumeIsolated
  • @preconcurrency协议合规
  • 遗留代理回调
  • 同步测试MainActor代码
线程安全原语
/skill axiom-synchronization
  • Mutex(iOS 18+)
  • OSAllocatedUnfairLock(iOS 16+)
  • 原子类型
  • 锁与Actor的选择
参数所有权
/skill axiom-ownership-conventions
  • borrowing/consuming修饰符
  • 非可复制类型(~Copyable)
  • ARC流量减少
  • consume运算符
并发性能分析
/skill axiom-concurrency-profiling
  • Swift Concurrency Instruments模板
  • Actor竞争诊断
  • 线程池耗尽
  • 任务可视化

Decision Tree

决策树

  1. Data races / actor isolation / @MainActor / Sendable? → swift-concurrency
  2. Writing async/await code? → swift-concurrency
  3. Swift 6 migration? → swift-concurrency
  4. assumeIsolated / @preconcurrency? → assume-isolated
  5. Mutex / lock / synchronization? → synchronization
  6. borrowing / consuming / ~Copyable? → ownership-conventions
  7. Profile async performance / actor contention? → concurrency-profiling
  8. Value type / ARC / generic optimization? → swift-performance
  1. 数据竞争 / Actor隔离 / @MainActor / Sendable相关问题?→ swift-concurrency
  2. 编写async/await代码?→ swift-concurrency
  3. Swift 6迁移?→ swift-concurrency
  4. assumeIsolated / @preconcurrency相关问题?→ assume-isolated
  5. Mutex / 锁 / 同步相关问题?→ synchronization
  6. borrowing / consuming / ~Copyable相关问题?→ ownership-conventions
  7. 分析异步性能 / Actor竞争?→ concurrency-profiling
  8. 值类型 / ARC / 泛型优化相关问题?→ swift-performance

Anti-Rationalization

常见误区纠正

ThoughtReality
"Just add @MainActor and it'll work"@MainActor has isolation inheritance rules. swift-concurrency covers all patterns.
"I'll use nonisolated(unsafe) to silence the warning"Silencing warnings hides data races. swift-concurrency shows the safe pattern.
"It's just one async call"Even single async calls have cancellation and isolation implications. swift-concurrency covers them.
"I know how actors work"Actor reentrancy and isolation rules changed in Swift 6.2. swift-concurrency is current.
"I'll fix the Sendable warnings later"Sendable violations cause runtime crashes. swift-concurrency fixes them correctly now.
错误想法实际情况
“只要加上@MainActor就能正常工作”@MainActor具有隔离继承规则。swift-concurrency涵盖所有相关模式。
“我用nonisolated(unsafe)来消除警告就行”消除警告会隐藏数据竞争问题。swift-concurrency提供安全的解决方案。
“只是一个简单的异步调用而已”即使是单个异步调用也涉及取消和隔离的影响。swift-concurrency涵盖这些内容。
“我知道Actor的工作原理”Swift 6.2中Actor的重入和隔离规则已发生变化。swift-concurrency内容是最新的。
“Sendable警告我之后再修复”Sendable违规会导致运行时崩溃。swift-concurrency能正确修复此类问题。

Critical Patterns

关键模式

Swift 6 Concurrency (swift-concurrency):
  • Progressive journey: single-threaded → async → concurrent → actors
  • @concurrent attribute for forced background execution
  • Isolated conformances
  • Main actor mode for approachable concurrency
  • 11 copy-paste patterns
Swift Performance (swift-performance):
  • ~Copyable for non-copyable types
  • Copy-on-write (COW) patterns
  • Value vs reference type decisions
  • ARC overhead reduction
  • Generic specialization
Swift 6并发(swift-concurrency):
  • 渐进式演进:单线程 → 异步 → 并发 → Actor
  • 用于强制后台执行的@concurrent属性
  • 隔离合规
  • 易用并发的主Actor模式
  • 11个可直接复制使用的模式
Swift性能(swift-performance):
  • 用于非可复制类型的~Copyable
  • 写时复制(COW)模式
  • 值类型与引用类型的选择
  • ARC开销减少
  • 泛型特化

Example Invocations

调用示例

User: "I'm getting 'data race' errors in Swift 6" → Invoke:
/skill axiom-swift-concurrency
User: "How do I use @MainActor correctly?" → Invoke:
/skill axiom-swift-concurrency
User: "My app is slow due to unnecessary copying" → Invoke:
/skill axiom-swift-performance
User: "Should I use async/await for this network call?" → Invoke:
/skill axiom-swift-concurrency
User: "How do I use assumeIsolated?" → Invoke:
/skill axiom-assume-isolated
User: "My delegate callback runs on main thread, how do I access MainActor state?" → Invoke:
/skill axiom-assume-isolated
User: "Should I use Mutex or actor?" → Invoke:
/skill axiom-synchronization
User: "What's the difference between os_unfair_lock and OSAllocatedUnfairLock?" → Invoke:
/skill axiom-synchronization
User: "What does borrowing do in Swift?" → Invoke:
/skill axiom-ownership-conventions
User: "How do I use ~Copyable types?" → Invoke:
/skill axiom-ownership-conventions
User: "My async code is slow, how do I profile it?" → Invoke:
/skill axiom-concurrency-profiling
User: "I think I have actor contention, how do I diagnose it?" → Invoke:
/skill axiom-concurrency-profiling
用户:“我在Swift 6中遇到了‘数据竞争’错误” → 调用:
/skill axiom-swift-concurrency
用户:“如何正确使用@MainActor?” → 调用:
/skill axiom-swift-concurrency
用户:“我的应用因不必要的复制操作而运行缓慢” → 调用:
/skill axiom-swift-performance
用户:“这个网络请求应该用async/await吗?” → 调用:
/skill axiom-swift-concurrency
用户:“如何使用assumeIsolated?” → 调用:
/skill axiom-assume-isolated
用户:“我的代理回调在主线程运行,如何访问MainActor状态?” → 调用:
/skill axiom-assume-isolated
用户:“我应该用Mutex还是Actor?” → 调用:
/skill axiom-synchronization
用户:“os_unfair_lock和OSAllocatedUnfairLock有什么区别?” → 调用:
/skill axiom-synchronization
用户:“Swift中的borrowing有什么作用?” → 调用:
/skill axiom-ownership-conventions
用户:“如何使用~Copyable类型?” → 调用:
/skill axiom-ownership-conventions
用户:“我的异步代码运行缓慢,如何分析它?” → 调用:
/skill axiom-concurrency-profiling
用户:“我怀疑存在Actor竞争,如何诊断?” → 调用:
/skill axiom-concurrency-profiling