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/understanding-improving-swiftui-performance.md
1# Understanding and Improving SwiftUI Performance (Summary)23Context: Apple guidance on diagnosing SwiftUI performance with Instruments and applying design patterns to reduce long or frequent updates.45## Core concepts67- SwiftUI is declarative; view updates are driven by state, environment, and observable data dependencies.8- View bodies must compute quickly to meet frame deadlines; slow or frequent updates lead to hitches.9- Instruments is the primary tool to find long-running updates and excessive update frequency.1011## Instruments workflow12131. Profile via Product > Profile.142. Choose the SwiftUI template and record.153. Exercise the target interaction.164. Stop recording and inspect the SwiftUI track + Time Profiler.1718## SwiftUI timeline lanes1920- Update Groups: overview of time SwiftUI spends calculating updates.21- Long View Body Updates: orange >500us, red >1000us.22- Long Platform View Updates: AppKit/UIKit hosting in SwiftUI.23- Other Long Updates: geometry/text/layout and other SwiftUI work.24- Hitches: frame misses where UI wasn’t ready in time.2526## Diagnose long view body updates2728- Expand the SwiftUI track; inspect module-specific subtracks.29- Set Inspection Range and correlate with Time Profiler.30- Use call tree or flame graph to identify expensive frames.31- Repeat the update to gather enough samples for analysis.32- Filter to a specific update (Show Calls Made by `MySwiftUIView.body`).3334## Diagnose frequent updates3536- Use Update Groups to find long active groups without long updates.37- Set inspection range on the group and analyze update counts.38- Use Cause graph ("Show Causes") to see what triggers updates.39- Compare causes with expected data flow; prioritize the highest-frequency causes.4041## Remediation patterns4243- Move expensive work out of `body` and cache results.44- Use `Observable()` macro to scope dependencies to properties actually read.45- Avoid broad dependencies that fan out updates to many views.46- Reduce layout churn; isolate state-dependent subtrees from layout readers.47- Avoid storing closures that capture parent state; precompute child views.48- Gate frequent updates (e.g., geometry changes) by thresholds.4950## Verification5152- Re-record after changes to confirm reduced update counts and fewer hitches.53