Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Diagnoses SwiftUI performance issues — slow rendering, janky scrolling, high CPU/memory — through code review and Instruments profiling guidance.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: swiftui-performance-audit3description: Audit and improve SwiftUI runtime performance from code review and architecture. Use for requests to diagnose slow rendering, janky scrolling, high CPU/memory usage, excessive view updates, or layout thrash in SwiftUI apps, and to provide guidance for user-run Instruments profiling when code review alone is insufficient.4---56# SwiftUI Performance Audit78## Quick start910Use this skill to diagnose SwiftUI performance issues from code first, then request profiling evidence when code review alone cannot explain the symptoms.1112## Workflow13141. 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`.1920## 1. Intake2122Collect:23- Target view or feature code.24- Symptoms and exact reproduction steps.25- Data flow: `@State`, `@Binding`, environment dependencies, and observable models.26- Whether the issue shows up on device or simulator, and whether it was observed in Debug or Release.2728Ask the user to classify the issue if possible:29- CPU spike or battery drain30- Janky scrolling or dropped frames31- High memory or image pressure32- Hangs or unresponsive interactions33- Excessive or unexpectedly broad view updates3435For the full profiling intake checklist, read `references/profiling-intake.md`.3637## 2. Code-First Review3839Focus on:40- Invalidation storms from broad observation or environment reads.41- Unstable identity in lists and `ForEach`.42- Heavy derived work in `body` or view builders.43- Layout thrash from complex hierarchies, `GeometryReader`, or preference chains.44- Large image decode or resize work on the main thread.45- Animation or transition work applied too broadly.4647Use `references/code-smells.md` for the detailed smell catalog and fix guidance.4849Provide:50- Likely root causes with code references.51- Suggested fixes and refactors.52- If needed, a minimal repro or instrumentation suggestion.5354## 3. Guide the User to Profile5556If code review does not explain the issue, ask for runtime evidence:57- A trace export or screenshots of the SwiftUI timeline and Time Profiler call tree.58- Device/OS/build configuration.59- The exact interaction being profiled.60- Before/after metrics if the user is comparing a change.6162Use `references/profiling-intake.md` for the exact checklist and collection steps.6364## 4. Analyze and Diagnose6566- Map the evidence to the most likely category: invalidation, identity churn, layout thrash, main-thread work, image cost, or animation cost.67- Prioritize problems by impact, not by how easy they are to explain.68- Distinguish code-level suspicion from trace-backed evidence.69- Call out when profiling is still insufficient and what additional evidence would reduce uncertainty.7071## 5. Remediate7273Apply targeted fixes:74- Narrow state scope and reduce broad observation fan-out.75- Stabilize identities for `ForEach` and lists.76- 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.77- Use `equatable()` only when equality is cheaper than recomputing the subtree and the inputs are truly value-semantic.78- Downsample images before rendering.79- Reduce layout complexity or use fixed sizing where possible.8081Use `references/code-smells.md` for examples, Observation-specific fan-out guidance, and remediation patterns.8283## 6. Verify8485Ask the user to re-run the same capture and compare with baseline metrics.86Summarize the delta (CPU, frame drops, memory peak) if provided.8788## Outputs8990Provide:91- A short metrics table (before/after if available).92- Top issues (ordered by impact).93- Proposed fixes with estimated effort.9495Use `references/report-template.md` when formatting the final audit.9697## References9899- Profiling intake and collection checklist: `references/profiling-intake.md`100- Common code smells and remediation patterns: `references/code-smells.md`101- Audit output template: `references/report-template.md`102- Add Apple documentation and WWDC resources under `references/` as they are supplied by the user.103- Optimizing SwiftUI performance with Instruments: `references/optimizing-swiftui-performance-instruments.md`104- Understanding and improving SwiftUI performance: `references/understanding-improving-swiftui-performance.md`105- Understanding hangs in your app: `references/understanding-hangs-in-your-app.md`106- Demystify SwiftUI performance (WWDC23): `references/demystify-swiftui-performance-wwdc23.md`107