SwiftUI Performance Audit
Quick start
Use this skill to diagnose SwiftUI performance issues from code first, then request profiling evidence when code review alone cannot explain the symptoms.
Workflow
- Classify the symptom: slow rendering, janky scrolling, high CPU, memory growth, hangs, or excessive view updates.
- If code is available, start with a code-first review using
references/code-smells.md.
- If code is not available, ask for the smallest useful slice: target view, data flow, reproduction steps, and deployment target.
- If code review is inconclusive or runtime evidence is required, guide the user through profiling with
references/profiling-intake.md.
- Summarize likely causes, evidence, remediation, and validation steps using
references/report-template.md.
1. Intake
Collect:
- Target view or feature code.
- Symptoms and exact reproduction steps.
- Data flow:
@State, @Binding, environment dependencies, and observable models.
- Whether the issue shows up on device or simulator, and whether it was observed in Debug or Release.
Ask the user to classify the issue if possible:
- CPU spike or battery drain
- Janky scrolling or dropped frames
- High memory or image pressure
- Hangs or unresponsive interactions
- Excessive or unexpectedly broad view updates
For the full profiling intake checklist, read references/profiling-intake.md.
2. Code-First Review
Focus on:
- Invalidation storms from broad observation or environment reads.
- Unstable identity in lists and
ForEach.
- Heavy derived work in
body or view builders.
- Layout thrash from complex hierarchies,
GeometryReader, or preference chains.
- Large image decode or resize work on the main thread.
- Animation or transition work applied too broadly.
Use references/code-smells.md for the detailed smell catalog and fix guidance.
Provide:
- Likely root causes with code references.
- Suggested fixes and refactors.
- If needed, a minimal repro or instrumentation suggestion.
3. Guide the User to Profile
If code review does not explain the issue, ask for runtime evidence:
- A trace export or screenshots of the SwiftUI timeline and Time Profiler call tree.
- Device/OS/build configuration.
- The exact interaction being profiled.
- Before/after metrics if the user is comparing a change.
Use references/profiling-intake.md for the exact checklist and collection steps.
4. Analyze and Diagnose
- Map the evidence to the most likely category: invalidation, identity churn, layout thrash, main-thread work, image cost, or animation cost.
- Prioritize problems by impact, not by how easy they are to explain.
- Distinguish code-level suspicion from trace-backed evidence.
- Call out when profiling is still insufficient and what additional evidence would reduce uncertainty.
5. Remediate
Apply targeted fixes:
- Narrow state scope and reduce broad observation fan-out.
- Stabilize identities for
ForEach and lists.
- Move heavy work out of
body into derived state updated from inputs, model-layer precomputation, memoized helpers, or background preprocessing. Use @State only for view-owned state, not as an ad hoc cache for arbitrary computation.
- Use
equatable() only when equality is cheaper than recomputing the subtree and the inputs are truly value-semantic.
- Downsample images before rendering.
- Reduce layout complexity or use fixed sizing where possible.
Use references/code-smells.md for examples, Observation-specific fan-out guidance, and remediation patterns.
6. 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:
- A short metrics table (before/after if available).
- Top issues (ordered by impact).
- Proposed fixes with estimated effort.
Use references/report-template.md when formatting the final audit.
References
- Profiling intake and collection checklist:
references/profiling-intake.md
- Common code smells and remediation patterns:
references/code-smells.md
- Audit output template:
references/report-template.md
- Add Apple documentation and WWDC resources under
references/ as they are supplied by the user.
- Optimizing SwiftUI performance with Instruments (Apple/WWDC resource, user-supplied)
- Understanding and improving SwiftUI performance (Apple Developer documentation, user-supplied)
- Understanding hangs in your app (Apple Developer documentation, user-supplied)
- Demystify SwiftUI performance — WWDC23 (Apple/WWDC resource, user-supplied)
- In addition to the references above, use web search to consult current Apple Developer documentation when Instruments workflows or SwiftUI performance guidance may have changed.
1---2name: swiftui-performance-audit3description: Audit SwiftUI runtime performance from code first. Use when diagnosing slow rendering, janky scrolling, expensive updates, or profiling needs.4---5
6# SwiftUI Performance Audit
7
8## Quick start
9
10Use this skill to diagnose SwiftUI performance issues from code first, then request profiling evidence when code review alone cannot explain the symptoms.
11
12## Workflow
13
141. Classify the symptom: slow rendering, janky scrolling, high CPU, memory growth, hangs, or excessive view updates.
152. If code is available, start with a code-first review using `references/code-smells.md`.
163. If code is not available, ask for the smallest useful slice: target view, data flow, reproduction steps, and deployment target.
174. If code review is inconclusive or runtime evidence is required, guide the user through profiling with `references/profiling-intake.md`.
185. Summarize likely causes, evidence, remediation, and validation steps using `references/report-template.md`.
19
20## 1. Intake
21
22Collect:
23
24- Target view or feature code.
25- Symptoms and exact reproduction steps.
26- Data flow: `@State`, `@Binding`, environment dependencies, and observable models.
27- Whether the issue shows up on device or simulator, and whether it was observed in Debug or Release.
28
29Ask the user to classify the issue if possible:
30
31- CPU spike or battery drain
32- Janky scrolling or dropped frames
33- High memory or image pressure
34- Hangs or unresponsive interactions
35- Excessive or unexpectedly broad view updates
36
37For the full profiling intake checklist, read `references/profiling-intake.md`.
38
39## 2. Code-First Review
40
41Focus on:
42
43- Invalidation storms from broad observation or environment reads.
44- Unstable identity in lists and `ForEach`.
45- Heavy derived work in `body` or view builders.
46- Layout thrash from complex hierarchies, `GeometryReader`, or preference chains.
47- Large image decode or resize work on the main thread.
48- Animation or transition work applied too broadly.
49
50Use `references/code-smells.md` for the detailed smell catalog and fix guidance.
51
52Provide:
53
54- Likely root causes with code references.
55- Suggested fixes and refactors.
56- If needed, a minimal repro or instrumentation suggestion.
57
58## 3. Guide the User to Profile
59
60If code review does not explain the issue, ask for runtime evidence:
61
62- A trace export or screenshots of the SwiftUI timeline and Time Profiler call tree.
63- Device/OS/build configuration.
64- The exact interaction being profiled.
65- Before/after metrics if the user is comparing a change.
66
67Use `references/profiling-intake.md` for the exact checklist and collection steps.
68
69## 4. Analyze and Diagnose
70
71- Map the evidence to the most likely category: invalidation, identity churn, layout thrash, main-thread work, image cost, or animation cost.
72- Prioritize problems by impact, not by how easy they are to explain.
73- Distinguish code-level suspicion from trace-backed evidence.
74- Call out when profiling is still insufficient and what additional evidence would reduce uncertainty.
75
76## 5. Remediate
77
78Apply targeted fixes:
79
80- Narrow state scope and reduce broad observation fan-out.
81- Stabilize identities for `ForEach` and lists.
82- Move heavy work out of `body` into derived state updated from inputs, model-layer precomputation, memoized helpers, or background preprocessing. Use `@State` only for view-owned state, not as an ad hoc cache for arbitrary computation.
83- Use `equatable()` only when equality is cheaper than recomputing the subtree and the inputs are truly value-semantic.
84- Downsample images before rendering.
85- Reduce layout complexity or use fixed sizing where possible.
86
87Use `references/code-smells.md` for examples, Observation-specific fan-out guidance, and remediation patterns.
88
89## 6. Verify
90
91Ask the user to re-run the same capture and compare with baseline metrics.
92Summarize the delta (CPU, frame drops, memory peak) if provided.
93
94## Outputs
95
96Provide:
97
98- A short metrics table (before/after if available).
99- Top issues (ordered by impact).
100- Proposed fixes with estimated effort.
101
102Use `references/report-template.md` when formatting the final audit.
103
104## References
105
106- Profiling intake and collection checklist: `references/profiling-intake.md`
107- Common code smells and remediation patterns: `references/code-smells.md`
108- Audit output template: `references/report-template.md`
109- Add Apple documentation and WWDC resources under `references/` as they are supplied by the user.
110- Optimizing SwiftUI performance with Instruments (Apple/WWDC resource, user-supplied)
111- Understanding and improving SwiftUI performance (Apple Developer documentation, user-supplied)
112- Understanding hangs in your app (Apple Developer documentation, user-supplied)
113- Demystify SwiftUI performance — WWDC23 (Apple/WWDC resource, user-supplied)
114- In addition to the references above, use web search to consult current Apple Developer documentation when Instruments workflows or SwiftUI performance guidance may have changed.