axiom-swift-performance

charleswiltgen/axiom · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swift-performance
0 commentsdiscussion
summary

Core Principle: Optimize Swift code by understanding language-level performance characteristics—value semantics, ARC behavior, generic specialization, and memory layout—to write fast, efficient code without premature micro-optimization.

skill.md

Swift Performance Optimization

Purpose

Core Principle: Optimize Swift code by understanding language-level performance characteristics—value semantics, ARC behavior, generic specialization, and memory layout—to write fast, efficient code without premature micro-optimization.

Swift Version: Swift 6.2+ (for InlineArray, Span, @concurrent) Xcode: 16+ Platforms: iOS 18+, macOS 15+

Related Skills:

  • axiom-performance-profiling — Use Instruments to measure (do this first!)
  • axiom-swiftui-performance — SwiftUI-specific optimizations
  • axiom-build-performance — Compilation speed
  • axiom-swift-concurrency — Correctness-focused concurrency patterns

When to Use This Skill

✅ Use this skill when

  • App profiling shows Swift code as the bottleneck (Time Profiler hotspots)
  • Excessive memory allocations or retain/release traffic
  • Implementing performance-critical algorithms or data structures
  • Writing framework or library code with performance requirements
  • Optimizing tight loops or frequently called methods
  • Dealing with large data structures or collections
  • Code review identifying performance anti-patterns

Quick Decision Tree

Performance issue identified?
├─ Profiler shows excessive copying?
│  └─ → Part 1: Noncopyable Types
│  └─ → Part 2: Copy-on-Write
├─ Retain/release overhead in Time Profiler?
│  └─ → Part 4: ARC Optimization
├─ Generic code in hot path?
│  └─ → Part 5: Generics & Specialization
├─ Collection operations slow?
│  └─ → Part 7: Collection Performance
├─ Async/await overhead visible?
│  └─ → Part 8: Concurrency Performance
├─ Struct vs class decision?
│  └─ → Part 3: Value vs Reference
└─ Memory layout concerns?
   └─ → Part 9: Memory Layout

The Four Principles of Swift Performance

From WWDC 2024-10217: Swift's low-level performance characteristics come down to four areas. Each maps to a Part in this skill.

Principle What It Costs Skill Coverage
Function Calls Dispatch overhead, optimization barriers Part 5 (Generics), Part 6 (Inlining)
Memory Allocation Stack vs heap, allocation frequency Part 3 (Value vs Reference), Part 7 (Collections)
Memory Layout Cache locality, padding, contiguity Part 9 (Memory Layout), Part 11 (Span)
Value Copying COW triggers, defensive copies, ARC traffic Part 1 (Noncopyable), Part 2 (COW), Part 4 (ARC)

Understanding which principle is causing your bottleneck determines which Part to use.


Part 1: Noncopyable Types (~Copyable)

Swift 6.0+ introduces noncopyable types for performance-critical scenarios where you want to avoid implicit copies.

When to Use

  • Large types that should never be copied (file handles, GPU buffers)
  • Types with ownership semantics (must be explicitly consumed)
  • Performance-critical code where copies are expensive

Basic Pattern

// Noncopyable type
struct FileHandle: ~Copyable {
    private let fd: Int32

    init(path: String) throws {
        self.fd = open(path, O_RDONLY)
        guard fd != -1 else { throw FileError.openFailed }
    }

    deinit {
        close(fd)
    }

    // Must explicitly consume
    consuming func close() {
        _ = consume self
    }
}

// Usage
func processFile() throws {
    let handle = try FileHandle(path: "/data.txt")
    // handle is automatically consumed at end of scope
    // Cannot accidentally copy handle
}

Ownership Annotations

// consuming - takes ownership, caller cannot use after
func process(consuming data: [UInt8]) {
    // data is consumed
}

// borrowing - temporary access without ownership
func validate(borrowing data: [UInt8]) -> Bool {
    // data can still be used by caller
    return data.count > 0
}

// inout - mutable access
func modify(inout data: [UInt8]) {
    data.append(0)
}

Performance Impact

  • Eliminates implicit copies: Compiler error instead of runtime copy
  • Zero-cost abstraction: Same performance as manual memory management
  • Use when: Type is expensive to copy (>64 bytes) and copies are rare

Part 2: Copy-on-Write (COW)

Swift collections use COW for efficient memory sharing. Understanding when copies happen is critical for performance.

How COW Works

var array1 = [1, 2, 3]  // Single allocation
var array2 = array1     // Share storage (no copy)
array2.append(4)        // Now copies (array1 modified array2)

For custom COW implementation, see Copy-Paste Pattern 1 (COW Wrapper) below.

Performance Tips

// ❌ Accidental copy in loop
for i in 0..<array.count {
    array[i] = transform(array[i])  // Copy on first mutation if shared!
}

// ✅ Reserve capacity first (ensures unique)
array.reserveCapacity(array.count)
for i in 0..<array.count {
    array[i] = transform(array[i])
}

// ❌ Multiple mutations trigger multiple uniqueness checks
array.append(1)
array.append(2)
array.append(3)

// ✅ Single reservation
array.reserveCapacity(array.count + 3)
array.append(contentsOf: [1, 2, 3])

Defensive Copies

From WWDC 2024-10217: Swift sometimes inserts defensive copies when it cannot prove a value won't be mutated through a shared reference.

class DataStore {
    var items: [Item] = []  // COW type stored in class
}

func process(_ store: DataStore) {
    for item in store.items {
        // Swift may defensively copy `items` because:
        // 1. store.items is a class property (another reference could mutate it)
        // 2. The loop needs a stable snapshot
        handle(item)
    }
}

How to avoid: Copy to a local variable first — one explicit copy instead of repeated defensive copies:

func process(_ store: DataStore) {
    let items = store.items  // One copy
    for item in items {
        handle(item)  // No more defensive copies
    }
}

In profiler: Defensive copies appear as unexpected swift_retain/swift_release pairs or Array.__allocating_init calls when you didn't expect allocation.


Part 3: Value vs Reference Semantics

Choosing between struct and class has significant performance implications.

Decision Matrix

Factor Use Struct Use Class
Size ≤ 64 bytes > 64 bytes or contains large data
Identity No identity needed Needs identity (===)
Inheritance Not needed Inheritance required
Mutation Infrequent Frequent in-place updates
Sharing No sharing needed Must be shared across scope

Small Structs (Fast)

// ✅ Fast - fits in registers, no heap allocation
struct Point {
    var x: Double  // 8 bytes
    var y: Double  // 8 bytes
}  // Total: 16 bytes - excellent for struct

struct Color {
    var r, g, b, a: UInt8  // 4 bytes total - perfect for struct
}

Large Structs (Slow)

// ❌ Slow - excessive copying
struct HugeData {
    var buffer: [UInt8]  // 1MB
    var metadata: String
}

how to use axiom-swift-performance

How to use axiom-swift-performance on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add axiom-swift-performance
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-swift-performance

The skills CLI fetches axiom-swift-performance from GitHub repository charleswiltgen/axiom and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/axiom-swift-performance

Reload or restart Cursor to activate axiom-swift-performance. Access the skill through slash commands (e.g., /axiom-swift-performance) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

User Story & Requirements Generation

Create detailed user stories, acceptance criteria, and feature specs

Example

Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios

Reduce spec writing time by 50%, ensure comprehensive coverage

Competitive Analysis

Research competitors, compare features, identify gaps

Example

Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities

Complete competitive research in 2 hours instead of 2 days

Roadmap Prioritization

Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs

Example

Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale

Make data-driven prioritization decisions faster

Stakeholder Communication

Draft PRDs, status updates, and stakeholder presentations

Example

Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement

Save 3-5 hours/week on communication overhead

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client
  • Access to product documentation and roadmap tools (Jira, Notion, etc.)
  • Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
  • Stakeholder contact information and communication channels

Time Estimate

30-60 minutes to see productivity improvements

Installation Steps

  1. 1.Install product management skill
  2. 2.Start with user story generation for known feature
  3. 3.Progress to competitive analysis: research 2-3 competitors
  4. 4.Use for roadmap prioritization: apply RICE/ICE scoring
  5. 5.Draft stakeholder communications and refine based on feedback
  6. 6.Build template library for recurring PM tasks
  7. 7.Share effective prompts with product team

Common Pitfalls

  • Not validating competitive research—verify facts before sharing
  • Accepting user stories without involving engineering team
  • Over-relying on frameworks without qualitative judgment
  • Not customizing outputs to company culture and communication style
  • Skipping stakeholder validation of generated requirements

Best Practices

✓ Do

  • +Validate research and competitive analysis with real data
  • +Collaborate with engineering when generating technical requirements
  • +Customize frameworks and templates to your company context
  • +Use skill for first drafts, refine with stakeholder input
  • +Document successful prompt patterns for PM tasks
  • +Combine AI efficiency with human judgment and intuition

✗ Don't

  • Don't publish competitive analysis without fact-checking
  • Don't finalize user stories without engineering review
  • Don't make prioritization decisions solely on AI scoring
  • Don't skip customer validation of generated requirements
  • Don't ignore company-specific context and culture

💡 Pro Tips

  • Provide context: company goals, constraints, customer feedback
  • Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
  • Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
  • Use skill for 70% generation + 30% customization to company needs

When to Use This

✓ Use When

Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.

✗ Avoid When

Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.

Learning Path

  1. 1Basic: user stories, feature specs, status updates
  2. 2Intermediate: competitive analysis, prioritization frameworks, PRDs
  3. 3Advanced: product strategy, go-to-market planning, OKR setting
  4. 4Expert: product vision, market positioning, business model innovation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.747 reviews
  • Harper Abebe· Dec 24, 2024

    axiom-swift-performance fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Michael Bansal· Dec 20, 2024

    axiom-swift-performance reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Isabella Ndlovu· Dec 20, 2024

    I recommend axiom-swift-performance for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Rahul Santra· Nov 19, 2024

    axiom-swift-performance fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Harper Taylor· Nov 11, 2024

    We added axiom-swift-performance from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Isabella Brown· Nov 11, 2024

    Useful defaults in axiom-swift-performance — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Isabella Lopez· Nov 11, 2024

    axiom-swift-performance has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Pratham Ware· Oct 10, 2024

    axiom-swift-performance has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Amina Li· Oct 2, 2024

    Keeps context tight: axiom-swift-performance is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Amelia Harris· Oct 2, 2024

    Registry listing for axiom-swift-performance matched our evaluation — installs cleanly and behaves as described in the markdown.

showing 1-10 of 47

1 / 5