Swiftui performance audit

From mouadja02/skills · View interactive version

Swiftui performance audit is an AI agent skill from the GitHub repository mouadja02/skills. Audits SwiftUI performance: rendering, scrolling, CPU and memory, unnecessary view updates, body re-evaluations, and layout thrashing, with Instruments guidance when code review is inconclusive. Use when a SwiftUI screen stutters, scrolls poorly, or uses too much CPU.

How to use this skill

Skill file

SwiftUI Performance Audit

Attribution: Sourced from steipete/agent-scripts by Peter Steinberger. Originally created by @Dimillian from Dimillian/Skills (2025-12-31).

When to Use

Overview

Audit SwiftUI view performance end-to-end, from instrumentation and baselining to root-cause analysis and concrete remediation steps.

Workflow Decision Tree

1. Code-First Review

Collect:

Focus on:

2. Guide the User to Profile

Explain how to collect data with Instruments:

3. Analyze and Diagnose

Prioritize likely SwiftUI culprits:

4. Remediate

Apply targeted fixes:

Common Code Smells (and Fixes)

Expensive formatters in `body`

// ❌ Slow allocation on every render
var body: some View {
    let number = NumberFormatter()
    Text(number.string(from: 42)!)
}

// ✅ Cached formatter
final class Formatters {
    static let number = NumberFormatter()
}

Unstable identity in ForEach

// ❌ UUID() per render — destroys identity
ForEach(items, id: \.self) { item in Row(item) }

// ✅ Stable Identifiable ID
ForEach(items) { item in Row(item) }

Sorting/filtering in body

// ❌ Runs on every body eval
List {
    ForEach(items.sorted(by: sortRule)) { item in Row(item) }
}

// ✅ Sort once before view updates
let sortedItems = items.sorted(by: sortRule)

Broad dependencies in observable models

// ❌ Whole view tree re-renders on any items change
@Observable class Model { var items: [Item] = [] }
var body: some View { Row(isFavorite: model.items.contains(item)) }

// ✅ Granular view models or per-item state

5. Verify

Ask the user to re-run the same capture and compare with baseline metrics.

Summarize the delta (CPU, frame drops, memory peak) if provided.

Outputs

Provide:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.