swiftui-performance-developer

3
0
Source

Audit and improve SwiftUI runtime performance through code review and Instruments guidance. Use for diagnosing slow rendering, janky scrolling, excessive view updates, or layout thrash in SwiftUI apps.

Install

mkdir -p .claude/skills/swiftui-performance-developer && curl -L -o skill.zip "https://mcp.directory/api/skills/download/3601" && unzip -o skill.zip -d .claude/skills/swiftui-performance-developer && rm skill.zip

Installs to .claude/skills/swiftui-performance-developer

About this skill

SwiftUI Performance Developer (Smart Router)

Purpose

Audit SwiftUI view performance through code review and provide guidance for Instruments profiling when needed.

When Auto-Activated

  • Diagnosing slow rendering, janky scrolling, high CPU/memory
  • Excessive view updates or layout thrash
  • Keywords: performance, slow, jank, hitch, laggy, stuttering, CPU, memory, update

Workflow Decision Tree

  1. Code provided -> Start with Code-First Review
  2. Only symptoms described -> Ask for code/context, then Code-First Review
  3. Code review inconclusive -> Guide user to profile with Instruments

Fundamental Performance Insight (WWDC24)

SwiftUI views are value types (structs) that describe UI state - they are NOT long-lived objects. Breaking up one view into multiple subviews doesn't hurt performance because views are just declarative descriptions.

Key insight: SwiftUI maintains an efficient data structure behind the scenes. When state changes, new view values are created and SwiftUI determines what actually needs updating. You don't need to compromise code organization for performance.

// ✅ GOOD - Splitting into subviews is FREE
var body: some View {
    VStack {
        HeaderView(title: title)        // Separate view = fine
        ContentView(items: items)       // Separate view = fine
        FooterView(action: saveAction)  // Separate view = fine
    }
}
// SwiftUI only updates the specific subview when its state changes

Code-First Review Focus

Look for these common performance issues:

State-Driven Updates (WWDC24)

SwiftUI tracks dependencies automatically. Any data a view reads in body becomes a dependency:

@Observable class PetModel {
    var name: String = ""      // ← If read in body, becomes dependency
    var hasAward: Bool = false // ← Only triggers update if actually read
}

struct PetRow: View {
    let pet: PetModel

    var body: some View {
        HStack {
            Text(pet.name)       // Dependency: name
            if pet.hasAward {    // Dependency: hasAward
                Image(systemName: "star.fill")
            }
        }
    }
}
// When pet.hasAward changes, SwiftUI calls body again automatically

Performance benefit: Only views that actually read changed data get updated.

View Invalidation Storms

// BAD - Broad state triggers all views
@Observable class Model {
    var items: [Item] = []
}

// GOOD - Granular per-item state
@Observable class ItemModel {
    var isFavorite: Bool
}

Unstable Identity in Lists

// BAD - id churn causes full re-render
ForEach(items, id: \.self) { item in Row(item) }

// GOOD - Stable identity
ForEach(items, id: \.id) { item in Row(item) }

Heavy Work in body

// BAD - Allocation every render
var body: some View {
    let formatter = NumberFormatter()  // slow
    Text(formatter.string(from: value))
}

// GOOD - Cached formatter
static let formatter = NumberFormatter()
var body: some View {
    Text(Self.formatter.string(from: value))
}

Sorting/Filtering in ForEach

// BAD - Re-sorts every body eval
ForEach(items.sorted(by: sortRule)) { Row($0) }

// GOOD - Pre-sorted collection
let sortedItems = items.sorted(by: sortRule)
ForEach(sortedItems) { Row($0) }

Large Images Without Downsampling

// BAD - Decodes full resolution on main thread
Image(uiImage: UIImage(data: data)!)

// GOOD - Downsample off main thread first

Common Code Smells

PatternProblemFix
NumberFormatter() in bodyAllocation per renderStatic cached formatter
.filter { } in ForEachRecomputes every renderPre-filter, cache result
id: \.self on non-stable valuesIdentity churnUse stable ID property
UUID() per renderNew identity every timeStore ID in model
GeometryReader deep in treeLayout thrashMove up or use fixed sizes
if condition { View } in ForEachVariable view count forces full buildUse opacity(0) or pre-filter
AnyView in List rowsHides identity and view countUse @ViewBuilder or concrete types

Instruments Profiling Guidance

When code review is inconclusive, guide user to profile:

  1. Record: Product > Profile, SwiftUI template (Release build)
  2. Reproduce: Exact interaction (scroll, navigate, animate)
  3. Capture: SwiftUI timeline + Time Profiler
  4. Analyze:
    • "Long View Body Updates" (orange >500us, red >1000us)
    • "Hitches" lane for frame misses
    • Time Profiler call tree for hot frames

Ask user for:

  • Trace export or screenshots
  • Device/OS/build configuration

Remediation Checklist

  • Narrow state scope (@State/@Observable closer to leaf views)
  • Stabilize identities for ForEach and lists
  • Move heavy work out of body (precompute, cache, @State)
  • Use equatable() for expensive subtrees
  • Downsample images before rendering
  • Reduce layout complexity or use fixed sizing

References

For detailed WWDC guidance:

  • references/demystify-swiftui-performance-wwdc23.md
  • references/optimizing-swiftui-performance-instruments.md
  • references/understanding-improving-swiftui-performance.md

Related Skills

  • ios-dev-guidelines -> General Swift/iOS patterns
  • swiftui-patterns-developer -> View structure and composition

Navigation: This skill provides SwiftUI performance audit patterns. For general iOS development, see ios-dev-guidelines.

Attribution: Patterns adapted from Dimillian/Skills repository. WWDC24 insights from "SwiftUI Essentials" session.

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

641968

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

590705

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

338397

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

318395

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

450339

fastapi-templates

wshobson

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

304231

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.