swift-runtime-performance
Use this skill when reviewing Swift code for runtime-level performance costs, including heap allocation, ARC traffic, stack vs heap storage, closure capture contexts, method dispatch, protocol witness dispatch, existentials vs generics, opaque types, copy-on-write, SIL optimizer output, unsafe memory boundaries, or module-boundary optimizer visibility. Do not use it for Swift Concurrency scheduling, SwiftUI rendering, app launch, or profiling workflows unless the question is specifically about Swift runtime costs.
Livsy90 · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Livsy90/iOS-Performance-Agent-Skills --skill swift-runtime-performance技能说明
name: swift-runtime-performance description: Use this skill when reviewing Swift code for runtime-level performance costs, including heap allocation, ARC traffic, stack vs heap storage, closure capture contexts, method dispatch, protocol witness dispatch, existentials vs generics, opaque types, copy-on-write, SIL optimizer output, unsafe memory boundaries, or module-boundary optimizer visibility. Do not use it for Swift Concurrency scheduling, SwiftUI rendering, app launch, or profiling workflows unless the question is specifically about Swift runtime costs.
Swift Runtime Performance
Purpose
Use this skill to review Swift code for runtime-level performance costs without turning every abstraction into a problem. Focus on concrete costs such as allocation, ARC traffic, dispatch, specialization, copying, optimizer visibility, and unsafe memory boundaries.
This skill should help the agent distinguish real hot-path runtime costs from theoretical micro-optimizations.
When to use this skill
Use this skill when the task involves Swift runtime behavior such as:
- heap allocation, stack vs heap storage, object layout, boxed values, or closure contexts;
- ARC retain/release traffic, ownership, lifetime, weak/unowned references, or closure captures;
- direct dispatch, class dispatch, Objective-C dispatch, witness dispatch, or dynamic dispatch in hot paths;
any Protocol,some Protocol, generics, type erasure, specialization, or unspecialized hot code;- copy-on-write collections, large values, custom COW storage, or repeated copies;
- optimized SIL inspection, compiler optimization, inlining, devirtualization, or specialization evidence;
- unsafe Swift, pointer lifetime, memory binding, aliasing, buffer mutation, or safe wrappers around unsafe regions;
- module boundaries that affect optimizer visibility,
@inlinable,@usableFromInline,@frozen, or public API resilience trade-offs.
When not to use this skill
Do not use this skill for:
- general Swift syntax or API usage questions with no runtime performance concern;
- app launch investigations where the main issue is pre-main, dyld, static initializers, SDK startup, first frame, or first interaction;
- SwiftUI performance issues where the main issue is identity, invalidation, state scope, layout, drawing, animation, or scrolling;
- Swift Concurrency issues where the main issue is task lifetime, actor isolation, MainActor responsiveness, cancellation, AsyncSequence cleanup, reentrancy, or executor behavior;
- profiling workflow questions where the main task is choosing tools, interpreting traces, designing signposts, XCTest metrics, MetricKit, or production signals;
- broad architecture questions unless there is a specific runtime cost in a hot path.
If another skill is more specific, route there first and use this skill only for the runtime subproblem.
Neighbor skill boundaries
Use these boundaries before applying runtime advice:
- Use
swift-concurrency-performancewhen the task centers on actors, tasks, MainActor, cancellation, AsyncSequence, continuations, task groups, executor behavior, or responsiveness under async work. - Use
ios-launch-performancewhen the task centers on cold launch, warm launch, pre-main, dyld, framework loading, static initializers, AppDelegate, SwiftUIApp, first frame, first interaction, or launch metrics. - Use
swiftui-performancewhen the task centers on SwiftUI body evaluation, invalidation, identity, state ownership, dependency scope,List,LazyVStack, layout, drawing, animation, or lifecycle work in views. - Use
ios-performance-profilingwhen the task centers on choosing Instruments templates, interpreting traces, XCTest metrics, MetricKit, signposts, memory graphs, hangs, hitches, CPU, allocations, disk I/O, networking, or production telemetry. - Use this skill when a neighboring task reveals a Swift runtime-level cost such as allocation churn, ARC traffic, existential boxing, witness dispatch, unspecialized generics, repeated COW copies, or unsafe memory boundaries.
Core principle
Do not optimize based only on how the source code looks.
First identify:
- whether the code is on a hot path;
- what runtime cost is suspected;
- whether the cost is visible in measurement, compiler output, or a small benchmark;
- whether the proposed change preserves semantics and improves the measured path;
- what trade-off the change introduces.
A runtime optimization is useful only when it reduces cost in a path that matters.
Runtime cost taxonomy
Classify the suspected issue before recommending a change.
Use these categories:
- Allocation — heap objects, boxes, closure contexts, existential containers, temporary objects, intermediate collections.
- ARC — retain/release traffic, closure captures, weak/unowned access, bridged object lifetime, reference-backed value storage.
- Dispatch — dynamic dispatch, witness dispatch, Objective-C dispatch, closure calls, missed devirtualization.
- Existentials and generics —
any,some, type erasure, generic specialization, unspecialized hot paths, boxing. - Copying — COW storage, large values, repeated collection mutation, defensive copies, bridging copies.
- Compiler optimization — inlining, specialization, devirtualization, module visibility, resilience boundaries, optimized SIL output.
- Unsafe boundary — pointer lifetime, binding, alignment, aliasing, mutation, escaping buffers, safe wrappers.
- Module boundary — public API visibility,
@inlinable,@usableFromInline,@frozen, ABI resilience, optimizer visibility.
Core workflow
- Locate the user-visible symptom. Identify whether the concern is latency, scrolling, repeated work, memory growth, CPU use, binary size, launch impact, or theoretical code review risk.
- Confirm the hot path. Ask whether the code runs frequently, touches many elements, blocks interaction, runs during startup, or appears in measurements.