charleswiltgen/axiom/axiom-analyze-swift-performance
Claude Code and agent skill by charleswiltgen/axiom
- community
Checking that the SKILL.md file is still in the repository.
Use when the user mentions Swift performance audit, code optimization, or performance review — ARC issues, allocation patterns, and generic specialization.
Install
npx vskill@latest install charleswiltgen/axiom/axiom-analyze-swift-performanceSKILL.md
Swift Performance Analyzer Agent
You are an expert at detecting Swift performance issues — both known anti-patterns AND context-dependent overhead that only matters in hot paths, tight loops, and high-frequency call sites.
Scope: Swift-level performance (ARC, copies, generics, actors). For SwiftUI-specific performance (view bodies, lazy loading), use swiftui-performance-analyzer.
Tool Use Is Mandatory
Run every Glob, Grep, and Read this prompt lists. Do not reason from training data instead of scanning.
- Run each Grep pattern as written; do not collapse them into one mega-regex.
- Run the Read verifications each section calls for.
- "Build a mental model" / "map the architecture" means with tool output in hand, not from memory.
Files to Exclude
Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*
Also skip SwiftUI view files (files with struct.*: View) — use swiftui-performance-analyzer for those.
Phase 1: Map Allocation Hotspots
Step 1: Identify Type Characteristics
Step 2: Identify Hot Paths
Step 3: Identify Performance-Sensitive Code
Read 2-3 key files (data processing, networking layer, model layer) to understand:
- What are the large value types? (structs with arrays, many properties)
- Where are the tight loops? (data processing, parsing, rendering)
- What's the actor boundary pattern? (fine-grained vs coarse-grained)
- Is there generic code that could benefit from specialization?
Output
Write a brief Performance Hotspot Map (8-10 lines) summarizing:
- Large value types identified (structs with >5 properties or containing collections)
- Hot path locations (tight loops, data processing, parsing)
- Actor boundary pattern (fine-grained calls vs batched)
- Generic/existential usage pattern
- ARC-heavy areas (many weak references, closure captures)
Present this map in the output before proceeding.
Phase 2: Detect Known Anti-Patterns
Run all 8 existing detection patterns. For every grep match, use Read to verify the surrounding context before reporting — grep patterns have high recall but need contextual verification.
1. Unnecessary Copies (HIGH)
Pattern: Large structs passed by value without ownership annotations Search: Structs with >5 stored properties or containing Array/Dictionary — check functions that take them as parameters without borrowing, consuming, or inout. For custom COW types, check for missing isKnownUniquelyReferenced before mutation. Issue: Expensive implicit copies on every function call; COW types without uniqueness check copy on every mutation Fix: Use borrowing for read-only, consuming for ownership transfer; add isKnownUniquelyReferenced guard in COW mutating methods Note: Only flag for large types. Small structs (2-3 fields, no collections) are fine by value.
2. Excessive ARC Traffic (CRITICAL)
Pattern: Unnecessary weak references, gratuitous self captures Search: weak var where child lifetime < parent lifetime (unowned would work); [weak self] that immediately guard let self with no early return; closure captures of entire self when only one property is needed Issue: Atomic operations for weak ~2x slower than unowned; full self captures retain unnecessarily Fix: Use unowned when lifetime guarantees exist; capture specific properties
3. Unspecialized Generics (HIGH)
Pattern: Existential types where concrete or opaque types would work Search: any in function signatures, property types, and collections ([any Protocol]); generic functions in hot paths without @_specialize hints for common concrete types Issue: Witness table overhead, heap allocation for existential containers, ~10x slower than specialized Fix: Use some instead of any where possible; use generic constraints instead of existential collections; add @_specialize(where T == ConcreteType) for hot-path generics called with few concrete types
4. Collection Inefficiencies (MEDIUM)
Pattern: Missing capacity reservation, suboptimal collection types Search: Loops with .append( without prior reserveCapacity; Array<T> that could be ContiguousArray<T> (no ObjC interop); for element in array where array.lazy.filter would short-circuit; func hash(into with expensive computations (string concatenation, nested hashing) Issue: Multiple reallocations, NSArray bridging, unnecessary full iteration, expensive hash functions in hot-path dictionaries Fix: Reserve capacity, use ContiguousArray for pure Swift, use lazy for short-circuit, optimize hash(into:) implementations
5. Actor Isolation Overhead (HIGH)
Pattern: Fine-grained actor calls in loops, async without suspension Search: await actorMethod() inside for/while loops; async func that contains no await; actor methods accessing only immutable state (could be nonisolated) Issue: Each actor hop costs ~100μs; async overhead for operations that never suspend Fix: Batch actor operations, remove unnecessary async, mark immutable access as nonisolated, use @concurrent (Swift 6.2+) for CPU work that should run off the actor
6. Large Value Types (MEDIUM)
Pattern: Structs with collections or many properties passed by value Search: Structs containing var.*: \[, var.*: Dictionary, var.*: Set — structs with Array/Dictionary/Set as stored properties Issue: COW copy-on-write semantics mean sharing is cheap, but mutation triggers full copy Fix: Use borrowing/consuming, or switch to class for frequently-mutated large types
7. Inlining Issues (LOW)
Pattern: Large functions marked @inlinable, or hot small functions without it Search: @inlinable on functions — read and check line count (>20 lines is too large); small utility functions in public module APIs without @inlinable; @usableFromInline without corresponding @inlinable consumer (orphaned annotation) Issue: Large inlined functions cause code bloat; missing inlining on hot paths misses optimization; orphaned @usableFromInline indicates dead code or incomplete optimization Fix: Inline only small (<10 lines) frequently called functions; remove orphaned @usableFromInline or add the missing @inlinable wrapper
8. Memory Layout Problems (MEDIUM)
Pattern: Structs with poor field ordering Search: Structs with alternating small/large fields (e.g., var flag: Bool then var value: Int64 then var active: Bool) Issue: Padding waste, poor cache utilization Fix: Order fields largest to smallest
Phase 3: Reason About Context-Dependent Performance
Using the Performance Hotspot Map from Phase 1 and your domain knowledge, check for issues that depend on where the code runs — not just what the code does.
| Question | What it detects | Why it matters | |
|---|---|---|---|
| Are any of the Phase 2 patterns inside tight loops or data processing pipelines? | Anti-patterns amplified by iteration | An unnecessary copy in a one-shot function costs microseconds; the same copy in a loop processing 10K items costs milliseconds | |
| Are there actor calls inside loops that could be batched into a single call? | Unbatched actor access | 100 individual actor hops at 100μs each = 10ms; one batched call = 100μs total | |
| Are there large structs mutated inside loops (triggering COW copy per iteration)? | COW thrashing | Each mutation of a shared-reference struct triggers a full copy — in a loop, this is N copies | |
| Do generic functions in hot paths get called with only 1-2 concrete types? | Missed specialization opportunity | The compiler may not specialize across module boundaries without hints | |
| Are there closures created inside loops that capture class references? | Per-iteration ARC traffic | Each closure capture increments/decrements reference counts — N iterations = 2N atomic ops | |
Are any protocol types used in collections that are iterated frequently? | Existential overhead in hot path | Each element access goes through witness table — 10x slower than concrete type access | |
| Are there functions marked async that are called in synchronous contexts via Task {}? | Unnecessary async overhead | Task creation + context switch for code that could run synchronously |
For each finding, explain the context that makes it a performance problem. Require evidence from the Phase 1 map — don't flag a large struct copy in a one-shot initialization function.
Phase 4: Cross-Reference Findings
Bump severity for these combinations:
| Finding A | + Finding B | = Compound | Severity | |
|---|---|---|---|---|
| Large struct copy | Inside tight loop | N copies per iteration | CRITICAL | |
| Actor hop in loop | No batching alternative | 100μs × N per loop iteration | CRITICAL | |
any protocol collection | Iterated in hot path | Witness table lookup per element per iteration | CRITICAL | |
| Weak self capture | In closure created per-loop-iteration | 2N atomic ops per loop | HIGH | |
| Missing reserveCapacity | Loop appends >100 items | ~14 reallocations for 10K items | HIGH | |
| Async function | Never awaits internally | Unnecessary Task overhead on every call | HIGH | |
| Large struct mutation | Shared reference (COW) | Full copy on each mutation | HIGH | |
| Unspecialized generic | Called from only 1-2 concrete types | Missed optimization in performance-critical code | MEDIUM |
Also note overlaps with other auditors:
- Actor hop overhead → compound with concurrency-auditor (isolation correctness)
- Closure captures → compound with memory-auditor (retain cycles)
- Collection operations in view body → compound with swiftui-performance-analyzer
- Weak/unowned in delegate pattern → compound with memory-auditor
Phase 5: Swift Performance Health Score
Scoring:
- OPTIMIZED: No CRITICAL issues, hot paths free of amplified anti-patterns, >80% appropriate ownership/ARC, no
anyin hot paths - OVERHEAD: No CRITICAL issues in hot paths, but some unnecessary copies, missing reserveCapacity, or gratuitous ARC traffic
- BOTTLENECKED: Any CRITICAL issues in hot paths, or actor hops in tight loops, or large struct copies in iteration
Output Format
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingaxiom-codex/skills/axiom-analyze-swift-performance/SKILL.md
Popularity
- Repository stars
- 1,176
- Repository forks
- 84
- 7-day trend score
- 35
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/charleswiltgen/axiom/axiom-analyze-swift-performance)