Axiom Analyze Swift Performance 标志

Axiom Analyze Swift Performance

社区热门
CharlesWiltgen
axiom-analyze-swift-performance

适用于用户提到 Swift 性能审计、代码优化或性能评审的情况,涵盖 ARC 问题、内存分配模式和泛型特化。

Add to TypingMind

概览

发布者CharlesWiltgen
代码仓库Axiom
技能名称axiom-analyze-swift-performance
星标数
1.2K
复刻数
86
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 CharlesWiltgen 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Axiom Analyze Swift Performance AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-analyze-swift-performance
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/CharlesWiltgen/Axiom.git /tmp/Axiom
mkdir -p .claude/skills
cp -r /tmp/Axiom/axiom-codex/skills/axiom-analyze-swift-performance .claude/skills/axiom-analyze-swift-performance
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Axiom Analyze Swift Performance,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Axiom Analyze Swift Performance。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Axiom Analyze Swift Performance 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.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

Glob: **/*.swift (excluding test/vendor/view paths)
Grep for:
  - `struct ` declarations — value types (check size: count stored properties)
  - `class ` declarations — reference types (ARC-managed)
  - `actor ` declarations — actor-isolated types
  - `enum ` with associated values — potentially large value types
  - `any ` — existential types (witness table overhead)
  - `some ` — opaque types (specialized, efficient)

Step 2: Identify Hot Paths

Grep for:
  - `for `, `while `, `forEach` — loops (potential hot paths)
  - `func.*(_ .*:` — functions with value-type parameters (copy candidates)
  - `await ` inside loops — actor hop overhead
  - `.append(`, `.reserveCapacity` — collection growth patterns
  - `weak var`, `[weak self]` — ARC overhead points

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.

QuestionWhat it detectsWhy it matters
Are any of the Phase 2 patterns inside tight loops or data processing pipelines?Anti-patterns amplified by iterationAn 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 access100 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 thrashingEach 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 opportunityThe compiler may not specialize across module boundaries without hints
Are there closures created inside loops that capture class references?Per-iteration ARC trafficEach 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 pathEach 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 overheadTask 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= CompoundSeverity
Large struct copyInside tight loopN copies per iterationCRITICAL
Actor hop in loopNo batching alternative100μs × N per loop iterationCRITICAL
any protocol collectionIterated in hot pathWitness table lookup per element per iterationCRITICAL
Weak self captureIn closure created per-loop-iteration2N atomic ops per loopHIGH
Missing reserveCapacityLoop appends >100 items~14 reallocations for 10K itemsHIGH
Async functionNever awaits internallyUnnecessary Task overhead on every callHIGH
Large struct mutationShared reference (COW)Full copy on each mutationHIGH
Unspecialized genericCalled from only 1-2 concrete typesMissed optimization in performance-critical codeMEDIUM

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

markdown
## Performance Health Score

| Metric | Value |
|--------|-------|
| Value type efficiency | N large structs, M with ownership annotations (Z%) |
| ARC discipline | N weak references, M appropriate (Z% correct weak/unowned) |
| Generic specialization | N `any` usages, M that could be `some` or concrete (Z% specialized) |
| Collection efficiency | N append loops, M with reserveCapacity (Z%) |
| Actor efficiency | N actor calls in loops, M batched (Z%) |
| Hot path cleanliness | N hot paths identified, M free of amplified anti-patterns (Z%) |
| **Health** | **OPTIMIZED / OVERHEAD / BOTTLENECKED** |

Scoring:

  • OPTIMIZED: No CRITICAL issues, hot paths free of amplified anti-patterns, >80% appropriate ownership/ARC, no any in 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

markdown
# Swift Performance Audit Results

## Performance Hotspot Map
[8-10 line summary from Phase 1]

## Summary
- CRITICAL: [N] issues
- HIGH: [N] issues
- MEDIUM: [N] issues
- LOW: [N] issues
- Phase 2 (anti-pattern detection): [N] issues
- Phase 3 (context reasoning): [N] issues
- Phase 4 (compound findings): [N] issues

## Performance Health Score
[Phase 5 table]

## Issues by Severity

### [SEVERITY] [Category]: [Description]
**File**: path/to/file.swift:line
**Phase**: [2: Detection | 3: Context | 4: Compound]
**Context**: [hot path / one-shot / loop body — from Phase 1 map]
**Issue**: What's wrong or suboptimal
**Impact**: Estimated cost (e.g., "~100μs × N iterations")
**Fix**: Code example showing the fix
**Cross-Auditor Notes**: [if overlapping with another auditor]

## Quick Wins
1. [Highest impact, easiest fix]
2. [Second highest impact]
3. [Third highest impact]

## Recommendations
1. [Immediate actions — CRITICAL fixes in hot paths]
2. [Short-term — HIGH fixes (ARC, generics, collections)]
3. [Long-term — architectural improvements from Phase 3 findings]
4. [Verification — profile with Instruments Time Profiler after fixes]

Output Limits

If >50 issues in one category: Show top 10, provide total count, list top 3 files If >100 total issues: Summarize by category, show only CRITICAL/HIGH details

False Positives (Not Issues)

  • Small structs (2-3 fields, no collections) passed by value — copy is cheaper than indirection
  • weak var delegate that is genuinely optional (delegate may be deallocated first)
  • any Protocol in cold paths (configuration, setup, one-shot initialization)
  • Arrays that grow to <100 items without reserveCapacity
  • async func that wraps a single await call (legitimate async wrapper)
  • ContiguousArray not used when ObjC bridging is needed
  • @inlinable absent on internal (non-public) functions
  • Large structs that are created once and never copied (stored in @State, let binding)

Related

For Instruments workflows: axiom-performance (skills/swift-performance.md) skill For SwiftUI-specific performance: swiftui-performance-analyzer agent For memory lifecycle issues: axiom-performance (skills/memory-debugging.md) skill For actor isolation patterns: axiom-concurrency skill For behavior-preserving clarity simplification: swift-simplifier agent (defer to it for clarity-only changes; this agent owns speed)

Invocation Examples

Prompts that should launch this agent:

Explicit command: Users can also invoke this agent directly with axiom-analyze-swift-performance

Scope

Automatically scans Swift code for performance anti-patterns - detects unnecessary copies, ARC overhead, unspecialized generics, collection inefficiencies, actor isolation costs, and memory layout issues that cause slowdowns and excessive allocations.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Axiom Analyze Swift Performance AI 技能有什么作用?

适用于用户提到 Swift 性能审计、代码优化或性能评审的情况,涵盖 ARC 问题、内存分配模式和泛型特化。

为什么在 TypingMind 中使用 Axiom Analyze Swift Performance?

因为您只需安装一次,就能搭配任何模型使用。Axiom Analyze Swift Performance 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Axiom Analyze Swift Performance?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-analyze-swift-performance。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Axiom Analyze Swift Performance?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Axiom Analyze Swift Performance 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Axiom Analyze Swift Performance 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Axiom Analyze Swift Performance AI 技能免费吗?

是的。CharlesWiltgen 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇