swift-concurrency-performance

在审查 Swift 并发的性能与响应性时使用,涵盖任务爆炸、Actor 切换、MainActor 瓶颈、取消、AsyncSequence 清理、continuations、重入、执行器行为、阻塞异步工作或影响 UI 延迟的异步工作。若非性能、响应性、取消或生命周期相关的并发问题,请勿使用。

仓库最近推送
GitHub Stars
122
Forks
11
Issues / PRs
0

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "swift-concurrency-performance":https://skillpi.com/zh/skills/deepskill-15b805a4c83a7e876efb0dacb9dcce2ebdb17db0474feec24b95b9735ffb6dbd。安装前核对上游来源和版本:https://github.com/Livsy90/iOS-Performance-Agent-Skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

在审查 Swift 并发的性能与响应性时使用,涵盖任务爆炸、Actor 切换、MainActor 瓶颈、取消、AsyncSequence 清理、continuations、重入、执行器行为、阻塞异步工作或影响 UI 延迟的异步工作。若非性能、响应性、取消或生命周期相关的并发问题,请勿使用。

0 下载

介绍来源: third_party · Livsy90 · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
输入和输出
翻译待完成,请参阅来源文档。
软件、账号及付费要求
来源文档未说明。
限制与区别
来源文档未说明。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: swift-concurrency-performance
description: Use this skill when reviewing Swift Concurrency performance and responsiveness, including task explosions, actor hopping, MainActor bottlenecks, cancellation, AsyncSequence cleanup, continuations, reentrancy, executor behavior, blocking async work, or async work that affects UI latency. Do not use it for general async/await syntax questions unless performance, responsiveness, cancellation, or lifetime is part of the task.

Swift Concurrency Performance

Purpose

Use this skill to review, diagnose, and improve Swift Concurrency code when async work affects UI responsiveness, throughput, memory, cancellation, task lifetime, actor contention, or correctness under load.

This skill is not a general Swift Concurrency tutorial. It is a performance and responsiveness review workflow.

When to use this skill

Use this skill when the task involves:

  • UI stalls, slow interactions, hangs, or frame drops related to async work;
  • excessive Task creation, task groups, detached tasks, or unstructured concurrency;
  • MainActor bottlenecks, actor hopping, actor queue buildup, or actor contention;
  • cancellation that does not stop work, navigation leaks, or tasks outliving their owner;
  • AsyncSequence, AsyncStream, long-running streams, buffering, or producer cleanup;
  • continuation bridges, delegate/callback wrappers, or async wrappers around legacy APIs;
  • blocking calls inside async contexts, semaphores, synchronous I/O, locks, or cooperative pool starvation;
  • actor reentrancy, duplicate in-flight work, cache stampedes, or inconsistent actor state after await;
  • Swift 6 isolation behavior, explicit isolation, @concurrent, nonisolated, or Sendable boundaries;
  • Instruments traces, logs, or production signals that point to concurrency-related latency, memory growth, or throughput loss.

When not to use this skill

Do not use this skill for:

  • basic async/await syntax questions with no performance, lifetime, or responsiveness concern;
  • general architecture discussions where concurrency is not part of the critical path;
  • purely SwiftUI rendering issues unless async lifecycle work contributes to the symptom;
  • launch performance unless async startup work, task lifetime, or actor isolation is part of the launch path;
  • runtime-level allocation, ARC, generics, or existential costs unless they interact with concurrency behavior;
  • server-side concurrency questions unless the task is specifically about Swift Concurrency performance patterns.

Prefer another skill when a more specific domain dominates the task:

  • use ios-launch-performance for app startup, first frame, first interaction, pre-main, dyld, or SDK launch work;
  • use swiftui-performance for SwiftUI invalidation, identity, layout, scrolling, or body cost;
  • use ios-performance-profiling when the main task is choosing or interpreting profiling tools;
  • use swift-runtime-performance for allocations, ARC traffic, dispatch, existentials, generics, or copy-on-write costs.

Core workflow

  1. Identify the user-visible symptom: UI stall, slow interaction, low throughput, memory growth, duplicate work, leaked task, missed cancellation, actor contention, or blocked cooperative threads.
  2. Locate the async boundary: Task, task group, actor method, MainActor, continuation, stream, lifecycle callback, delegate bridge, or legacy blocking API.
  3. Determine the lifetime owner: view, view model, service, actor, request, app session, stream consumer, or detached background process.
  4. Separate required work from optional or deferrable work.
  5. Check whether concurrency is being used to express structure, isolation, and cancellation rather than as a vague performance fix.
  6. Look for blocking work inside async contexts.
  7. Check whether work that affects UI state is isolated narrowly and whether CPU-heavy work is kept off the main actor.
  8. Check cancellation propagation, especially across task groups, streams, continuations, loops, and navigation lifetimes.
  9. Check for actor reentrancy after every await inside actor-isolated methods.
  10. Propose the smallest safe change that improves lifetime, cancellation, isolation, or throughput.
  11. Include a validation path before calling the change a performance improvement.

Decision rules

  • Treat async as suspension, not as automatic background execution.
  • Do not assume concurrency improves performance. More tasks can increase scheduling overhead, memory pressure, actor contention, and cancellation complexity.
  • Prefer structured concurrency when the parent owns the lifetime of the work.
  • Use unstructured tasks only when the lifetime is deliberately independent and cancellation ownership is explicit.
  • Use Task.detached only as an explicit escape hatch from inherited context, priority, task-local values, and actor isolation.
  • Bound parallel work when the input size can grow.
  • Keep MainActor work short and focused on UI state, presentation coordination, and main-thread-only APIs.
  • Move CPU-heavy work outside main-actor isolation, but do not cross isolation boundaries casually.
  • Batch actor calls on hot paths when repeated hops dominate latency.
  • After an await inside an actor, assume actor state may have changed.
  • Use checked continuations by default and verify every path resumes exactly once.
  • Treat stream termination and producer cleanup as part of the API contract.
  • Prefer cancellation-aware loops and pipelines for long-running or high-volume work.
  • Connect every performance claim to evidence or a validation plan.

Gotchas

  • Do not recommend adding async or Task simply because code is slow.
  • Do not move work off the MainActor if the API or UI state must remain main-actor isolated.
  • Do not leave CPU-heavy computation in a @MainActor type just because the type also owns UI state.
  • Do not use Task.detached to silence isolation errors without explaining the lifetime, cancellation, priority, and data-safety consequences.
  • Do not create one child task per item for large or unbounded collections without limiting concurrency.
  • Do not swallow cancellation with broad catch blocks.
  • Do not assume cancelling a parent automatically stops legacy callbacks, streams, delegates, or manually retained producers.
  • Do not wrap a blocking API in async if the underlying work still blocks a cooperative executor thread.
  • Do not treat actor isolation as a duplicate-work prevention mechanism when the actor method suspends during a cache miss.
  • Do not use unsafe continuations unless profiling shows checked continuation overhead matters and the resume contract is proven.
  • Do not call an optimization successful without before/after validation.

Reference routing

Read these only when relevant:

  • references/concurrency-runtime.md — read when the task needs the mental model for tasks, suspension, cooperative executors, actor executors, priorities, structured concurrency, or why blocking async code is harmful.
  • references/mainactor-responsiveness.md — read when the task involves MainActor, @MainActor types, UI state, view models, main-thread stalls, @concurrent, or moving CPU-heavy work away from UI isolation.
  • references/task-lifetime-and-structure.md — read when the task involves structured concurrency, unstructured tasks, task ownership, Task {}, Task.detached, view/view-model lifetimes, or tasks that outlive their owner.
  • references/cancellation-and-task-lifetime.md — read when the task involves navigation cancellation, long-running work, cancellation propagation, cancellation swallowed by catch, task groups, streams, or cancellation tests.
  • references/bounded-task-groups.md — read when the task involves withTaskGroup, withThrowingTaskGroup, parallel mapping, fan-out work, memory spikes, or limiting concurrency.
  • references/actor-reentrancy.md — read when the task involves actor-isolated state, duplicate network requests, cache stampedes, state checks before and after await, or actor queue buildup.
  • references/swift-6-isolation.md — read when the task involves Swift 6 isolation behavior, default actor isolation, @concurrent, nonisolated, Sendable boundaries, or migration-related performance regressions.
  • references/blocking-legacy-apis.md — read when the task involves semaphores, synchronous file I/O, blocking networking, locks, callback APIs, old SDKs, or async wrappers around blocking work.
  • references/continuation-safety.md — read when the task involves withCheckedContinuation, withCheckedThrowingContinuation, delegate bridges, callback wrappers, timeout paths, cancellation paths, or exactly-once resume guarantees.
  • references/asyncsequence-and-stream-cleanup.md — read when the task involves AsyncSequence, AsyncStream, AsyncThrowingStream, long-running streams, buffering, producer lifetime, onTermination, or for await loops.
  • references/diagnostics-and-instruments.md — read when the user provides traces, logs, measurements, production signals, or asks how to validate concurrency-related performance changes.

Validation expectations

Recommend validation that matches the suspected issue:

  • use Instruments when the symptom involves UI stalls, actor contention, task lifetime, blocked threads, or high task counts;
  • use signposts when comparing before/after latency across async boundaries;
  • use cancellation tests when work should stop after navigation, deallocation, timeout, or parent cancellation;
  • use memory graphs or allocation instruments when streams, task groups, or long-lived tasks may retain producers or large values;
  • use logs with task identifiers or request identifiers when checking duplicate in-flight work;
  • use XCTest performance tests only when the workload is repeatable enough to produce meaningful comparisons;
  • use production metrics when local traces cannot reproduce tail latency or rare stuck tasks.

Do not present a concurrency refactor as a performance win unless there is a clear validation path.

Output expectations

When reviewing code, respond with:

  1. Finding — the likely concurrency performance, lifetime, isolation, or responsiveness issue.
  2. Why it matters — the impact on UI latency, throughput, memory, cancellation, actor contention, or correctness.
  3. Evidence — the code pattern, trace symptom, lifecycle mismatch, missing cancellation path, blocking call, actor hop pattern, or continuation/stream contract issue.
  4. Recommended change — the smallest safe change first; avoid broad rewrites unless the design itself causes the issue.
  5. Trade-offs — what the change improves and what it may complicate.
  6. Validation — how to verify the result with Instruments, signposts, cancellation tests, logs, memory tools, UI behavior, or production metrics.

When the task asks for an investigation plan, respond with:

  1. the symptom to reproduce;
  2. the suspected async boundary;
  3. the likely lifetime or isolation owner;
  4. the first trace or log to collect;
  5. the signal that would confirm or reject the hypothesis;
  6. the smallest next code area to inspect.

When the task asks for an explanation, keep it practical:

  1. explain the model briefly;
  2. show one concrete iOS or Swift example only if needed;
  3. name the common misconception;
  4. include a validation or debugging technique.

版本历史

  1. 1.0.0 GitHub ↗

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 针对Swift并发性能这一iOS开发中的高频核心痛点,提供了系统性的诊断和优化方案
  • 覆盖UI响应性、任务生命周期、Actor隔离、取消机制等关键并发问题场景
  • 提供了详尽的决策规则和常见陷阱(gotchas),具有极强的实践指导价值
触发精准95/100

亮点

  • 触发词精准完整,when to use和when not to use部分清晰界定了适用边界
  • 明确区分了并发性能问题与一般async/await语法问题的界限
  • 提供了与其他相关技能(reference routing)的明确分工
结构规范90/100

亮点

  • 结构清晰完整,包含workflow、decision rules、gotchas、validation expectations等关键章节
  • frontmatter完整,单文件内容详实但不过长
  • 提供了端到端的诊断流程和输出期望
执行可靠88/100

亮点

  • 提供了具体的验证方法和工具建议(Instruments、signposts、cancellation tests等)
  • 覆盖主要异常场景和边界情况
  • 强调最小化变更和验证的重要性,避免盲目优化
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

来源文档未说明。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。