From apple-dev
Diagnose SwiftUI performance issues including unnecessary re-renders, view identity problems, and slow body evaluations. Use when SwiftUI views are slow, janky, or re-rendering too often.
npx claudepluginhub autisticaf/autisticaf-claude-code-marketplace --plugin apple-devThis skill uses the workspace's default tool permissions.
> **First step:** Tell the user: "performance-swiftui-debugging skill loaded."
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
First step: Tell the user: "performance-swiftui-debugging skill loaded."
Systematic guide for diagnosing and fixing SwiftUI performance problems: unnecessary view re-evaluations, identity issues, expensive body computations, and lazy loading mistakes.
Use this skill when the user:
Self._printChanges() or view debugging@Observable or ObservableObject performance differencesAnyView and asks about performance implicationsWhat SwiftUI performance problem are you seeing?
|
+- Views re-render when they should not
| +- Read references/body-reevaluation.md
| +- Self._printChanges() to identify which property changed
| +- @Observable vs ObservableObject observation differences
| +- Splitting views to narrow observation scope
|
+- Scrolling is slow / choppy (lists, grids)
| +- Read references/lazy-loading.md
| +- VStack vs LazyVStack, ForEach without lazy container
| +- List prefetching, grid cell reuse
|
+- Views lose state unexpectedly / animate when they should not
| +- Read references/view-identity.md
| +- Structural vs explicit identity
| +- .id() misuse, conditional view branching
|
+- Known pitfall (AnyView, DateFormatter in body, etc.)
| +- Read references/common-pitfalls.md
| +- AnyView type erasure, object creation in body
| +- Over-observation, expensive computations
|
+- General "my SwiftUI app is slow" (unknown cause)
| +- Start with references/body-reevaluation.md, then references/common-pitfalls.md
| +- Use Instruments SwiftUI template (see Debugging Tools below)
| API / Technique | Minimum Version | Reference |
|---|---|---|
Self._printChanges() | iOS 15 | references/body-reevaluation.md |
@Observable | iOS 17 / macOS 14 | references/body-reevaluation.md |
@ObservableObject | iOS 13 | references/body-reevaluation.md |
LazyVStack / LazyHStack | iOS 14 | references/lazy-loading.md |
LazyVGrid / LazyHGrid | iOS 14 | references/lazy-loading.md |
.id() modifier | iOS 13 | references/view-identity.md |
| Instruments SwiftUI template | Xcode 14+ | SKILL.md |
os_signpost | iOS 12 | SKILL.md |
| # | Mistake | Fix | Details |
|---|---|---|---|
| 1 | Large ForEach inside VStack or ScrollView without lazy container | Wrap in LazyVStack -- eager VStack creates all views upfront | references/lazy-loading.md |
| 2 | Using AnyView to erase types | Use @ViewBuilder, Group, or concrete generic types -- AnyView defeats diffing | references/common-pitfalls.md |
| 3 | Creating objects in body (DateFormatter(), NumberFormatter()) | Use static let shared instances or @State for mutable objects | references/common-pitfalls.md |
| 4 | Observing entire model when only one property is needed | Split into smaller @Observable objects or extract subviews | references/body-reevaluation.md |
| 5 | Unstable .id() values causing full view recreation every render | Use stable identifiers (database IDs, UUIDs), never array indices or random values | references/view-identity.md |
Add to any view body to see what triggered re-evaluation:
var body: some View {
let _ = Self._printChanges()
// ... view content
}
Output reads: ViewName: @self, @identity, _propertyName changed.
See references/body-reevaluation.md for full interpretation guide.
import os
private let perfLog = OSLog(subsystem: "com.app.perf", category: "SwiftUI")
var body: some View {
let _ = os_signpost(.event, log: perfLog, name: "MyView.body")
// ... view content
}
View in Instruments with the os_signpost instrument to count body evaluations per second.
.id() values (random, Date(), array index on mutable arrays)if/else) do not cause unnecessary view destructionForEach uses stable, unique identifiers from the model@Observable classes preferred over ObservableObject (iOS 17+)@State changes that trigger body re-evaluationLazyVStack / LazyHStack, not VStack / HStackList or lazy stack used for 50+ items.frame(maxHeight: .infinity) on children inside lazy containers (defeats laziness)AnyView type erasure (use @ViewBuilder or Group)body (DateFormatter, NSPredicate, view models)task { } or Task.detachedAsyncImage or .resizable() with proper sizing, not raw UIImage decoding in body| File | Content |
|---|---|
| references/view-identity.md | Structural vs explicit identity, .id() usage, conditional branching |
| references/body-reevaluation.md | What triggers body, _printChanges(), @Observable vs ObservableObject |
| references/lazy-loading.md | Lazy vs eager containers, List, ForEach, grid performance |
| references/common-pitfalls.md | AnyView, object creation in body, over-observation, expensive computations |
| performance-profiling skill | General Instruments profiling (Time Profiler, Memory, Energy) |