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.
references/demystify-swiftui-performance-wwdc23.md
1# Demystify SwiftUI Performance (WWDC23) (Summary)23Context: WWDC23 session on building a mental model for SwiftUI performance and triaging hangs/hitches.45## Performance loop67- Measure -> Identify -> Optimize -> Re-measure.8- Focus on concrete symptoms (slow navigation, broken animations, spinning cursor).910## Dependencies and updates1112- Views form a dependency graph; dynamic properties are a frequent source of updates.13- Use `Self._printChanges()` in debug only to inspect extra dependencies.14- Eliminate unnecessary dependencies by extracting views or narrowing state.15- Consider `@Observable` for more granular property tracking.1617## Common causes of slow updates1819- Expensive view bodies (string interpolation, filtering, formatting).20- Dynamic property instantiation and state initialization in `body`.21- Slow identity resolution in lists/tables.22- Hidden work: bundle lookups, heap allocations, repeated string construction.2324## Avoid slow initialization in view bodies2526- Don’t create heavy models synchronously in view bodies.27- Use `.task` to fetch async data and keep `init` lightweight.2829## Lists and tables identity rules3031- Stable identity is critical for performance and animation.32- Ensure a constant number of views per element in `ForEach`.33- Avoid inline filtering in `ForEach`; pre-filter and cache collections.34- Avoid `AnyView` in list rows; it hides identity and increases cost.35- Flatten nested `ForEach` when possible to reduce overhead.3637## Table specifics3839- `TableRow` resolves to a single row; row count must be constant.40- Prefer the streamlined `Table` initializer to enforce constant rows.41- Use explicit IDs for back deployment when needed.4243## Debugging aids4445- Use Instruments for hangs and hitches.46- Use `_printChanges` to validate dependency assumptions during debug.47