swiftui-performance-developer
Performance auditor for SwiftUI, providing code review and profiling guidance to eliminate lag.
Install
mkdir -p .claude/skills/swiftui-performance-developer && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3601" && unzip -o skill.zip -d .claude/skills/swiftui-performance-developer && rm skill.zipInstalls to .claude/skills/swiftui-performance-developer
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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.Key capabilities
- →Audit SwiftUI code for performance bottlenecks
- →Identify excessive view updates and layout thrash
- →Provide guidance for Instruments profiling
- →Detect unstable identities in ForEach loops
- →Recommend caching strategies for heavy computations
How it works
The skill reviews code for common SwiftUI performance anti-patterns and provides a decision tree to guide users from code-level fixes to deep-dive profiling with Instruments.
Inputs & outputs
When to use swiftui-performance-developer
- →Diagnosing slow SwiftUI rendering
- →Fixing janky scrolling in lists
- →Reducing layout thrash
- →Profiling CPU spikes in UI
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
- Code provided -> Start with Code-First Review
- Only symptoms described -> Ask for code/context, then Code-First Review
- 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
| Pattern | Problem | Fix |
|---|---|---|
NumberFormatter() in body | Allocation per render | Static cached formatter |
.filter { } in ForEach | Recomputes every render | Pre-filter, cache result |
id: \.self on non-stable values | Identity churn | Use stable ID property |
UUID() per render | New identity every time | Store ID in model |
GeometryReader deep in tree | Layout thrash | Move up or use fixed sizes |
if condition { View } in ForEach | Variable view count forces full build | Use opacity(0) or pre-filter |
AnyView in List rows | Hides identity and view count | Use @ViewBuilder or concrete types |
Instruments Profiling Guidance
When code review is inconclusive, guide user to profile:
- Record: Product > Profile, SwiftUI template (Release build)
- Reproduce: Exact interaction (scroll, navigate, animate)
- Capture: SwiftUI timeline + Time Profiler
- 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/@Observablecloser to leaf views) - Stabilize identities for
ForEachand 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.mdreferences/optimizing-swiftui-performance-instruments.mdreferences/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.
When not to use it
- →When the issue is unrelated to SwiftUI rendering performance
- →When the user has not provided code or specific symptoms
Limitations
- →Requires code context for accurate analysis
- →Instruments guidance is secondary to code-first review
How it compares
It applies specific WWDC-based performance insights to SwiftUI code rather than relying on generic iOS debugging techniques.
Compared to similar skills
swiftui-performance-developer side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| swiftui-performance-developer (this skill) | 1 | 6mo | No flags | Intermediate |
| tests-developer | 1 | 6mo | Review | Intermediate |
| code-coverage-with-gcov | 15 | 4mo | Review | Intermediate |
| angular-best-practices | 21 | 3mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by anyproto
View all by anyproto →You might also like
tests-developer
anyproto
Smart router to testing patterns and practices. Use when writing unit tests, creating mocks, testing edge cases, or working with Swift Testing and XCTest frameworks.
code-coverage-with-gcov
gadievron
Add gcov code coverage instrumentation to C/C++ projects
angular-best-practices
sickn33
Angular performance optimization and best practices guide. Use when writing, reviewing, or refactoring Angular code for optimal performance, bundle size, and rendering efficiency.
react-best-practices
redpanda-data
Client-side React performance optimization patterns.
react-component-performance
Dimillian
Analyze and optimize React component performance issues (slow renders, re-render thrash, laggy lists, expensive computations). Use when asked to profile or improve a React component, reduce re-renders, or speed up UI updates in React apps.
moai-workflow-testing
modu-ai
Comprehensive development workflow specialist combining DDD testing, debugging, performance optimization, code review, PR review, and quality assurance into unified development workflows