Profiles and fixes SwiftUI runtime performance issues including slow rendering, scrolling hitches, excessive body updates, identity churn, layout spikes, and Observation invalidation using Instruments and code review.
Ships in all-ios-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Audit SwiftUI view performance from a reproducible symptom to measured
remediation. Route animation design to swiftui-animation, production telemetry
to metrickit, ownership/leak analysis to ios-memgraph-analysis, navigation
behavior to swiftui-navigation, state architecture to swiftui-patterns, and
layout construction to swiftui-layout-components.
Use this triage list for both code and trace analysis:
bodyMap each suspect from the triage list to exact code. Report likely causes with code references, but label them code-backed hypotheses until a trace confirms cost. Propose a minimal repro or measurement when evidence is missing.
Use the SwiftUI Instruments template on a Release build and real device when possible. Reproduce the exact interaction, capturing SwiftUI lanes, Time Profiler, and Hangs/Hitches as relevant. Ask for the trace or screenshots of the lanes and call tree.
Apply the same triage list to trace evidence. Correlate long or frequent SwiftUI updates with the Time Profiler call tree and the reproduced interaction. Separate trace-backed findings from code-backed hypotheses and name the next measurement that would resolve remaining uncertainty.
Apply targeted fixes:
@State/@Observable closer to leaf views).ForEach and lists.body into model-layer precomputation, an explicit derived
value updated when its inputs change, a memoized helper, or background processing.
Use @State only when the view owns both the value and its update lifecycle; it is
not a generic cache for arbitrary computation.equatable() only when equality is cheaper than recomputing the subtree and
the compared inputs have stable value semantics.| Smell | Evidence to seek | Targeted fix |
|---|---|---|
Formatter, sort, filter, or decode in body | Long/frequent body updates with matching call-tree cost | Recompute when inputs change; downsample/decode off the main actor |
UUID() or unstable id: \.self | Recreated rows, lost state, excess updates | Use stable model identity |
Root if/else swaps | State reset or update spikes when toggled | Localize conditional content/modifiers when semantics allow |
| Broad model reads | Many unrelated views update together | Pass narrow values or move reads into focused child views |
| Geometry writes during layout | Repeating layout/update cycle | Threshold changes or replace the feedback path with stable layout |
Ask the user to re-run the same capture and compare with baseline metrics. Summarize the delta (CPU, frame drops, memory peak) if provided.
Provide:
Use the SwiftUI template in Instruments (Cmd+I to profile). Current SwiftUI lanes include Update Groups, Long View Body Updates, Long Representable Updates / Representable Updates, Other Long Updates / Other Updates, and the Cause & Effect Graph. Correlate those with Time Profiler and Hangs/Hitches.
Add Self._printChanges() in debug builds to log which property triggered a view update:
#if DEBUG
let _ = Self._printChanges() // "MyView: @self, _count changed."
#endif
See references/optimizing-swiftui-performance-instruments.md for the full profiling workflow.
Identity controls view lifetime and state. Use stable model IDs in repeated
content and reserve .id(_:) changes for intentional resets. Prefer
@ViewBuilder or generic composition over AnyView in profiled hot rows. Treat
root conditional branches as suspects—not automatic defects—when evidence shows
state churn or expensive recreation.
Text(title).foregroundStyle(isHighlighted ? .yellow : .primary)
ForEach(items) { item in Row(item: item).id(item.stableID) }
Use lazy containers when profiling shows eager construction, layout, or update
work is material; there is no universal item-count threshold. Route grid/list
construction choices to swiftui-layout-components.
Guardrails:
onAppear because of prefetching; do not make onAppear the only setup point, and treat onAppear/onDisappear as visibility signals, not lifetime guarantees.ForEach, keep each element to a constant number of top-level subviews, and use -LogForEachSlowPath YES while debugging.Layout, or thresholded changes.Observation tracks properties read during view evaluation. Reduce fan-out by passing narrow derived values or moving reads into focused child views.
struct ProfileView: View {
let model: ProfileModel
var body: some View {
VStack {
NameRow(model: model); EmailRow(model: model) // each tracks only its own reads
AvatarView(model: model); SettingsForm(model: model)
}
}
}
Cheap computed values can remain derived; expensive transformations need an
explicit owner, input set, and refresh trigger. Do not add view models as a
performance ritual—measure first and route general state design to
swiftui-patterns.
@Observable models or narrow reads with computed properties/closures.ScrollView items. Prefer stable sizing, custom layout, or thresholded .onGeometryChange (iOS 16+).DateFormatter/NumberFormatter inside body. Make them static or move them outside the view.Equatable and use .animation(_:value:) or .animation(_:body:).List without identifiers. Use id: or Identifiable so SwiftUI diffs instead of rebuilding the entire list.@State wrapper classes. Use plain @State with structs; wrapping a value type in a class defeats value semantics.MainActor with synchronous I/O. Move file reads, large parsing, and decoding off the main actor; reserve Task.detached for deliberate actor-inheritance breaks.DateFormatter/NumberFormatter allocations inside bodyIdentifiable items or explicit id:@Observable models expose only the properties views actually readMainActor (image processing, parsing)onAppear as the only setup point.animation(_:value:) for value-bound changes or .animation(_:body:) for narrower modifier scope@State is not used as an unspecified cache; every derived value has an explicit owner and refresh triggerequatable() is used only when comparison is cheaper than recomputation and inputs have stable value semantics@Observable view models are @MainActor-isolated; types crossing concurrency boundaries are Sendableevals/evals.json (opens in a new tab)references/demystify-swiftui-performance-wwdc23.md (opens in a new tab)references/optimizing-swiftui-performance-instruments.md (opens in a new tab)references/understanding-hangs-in-your-app.md (opens in a new tab)references/understanding-improving-swiftui-performance.md (opens in a new tab)references/wwdc-session-sources.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
95 skills in this plugin
/accessorysetupkitDiscover and configure Bluetooth and Wi-Fi accessories using AccessorySetupKit. Use when presenting a privacy-preserving accessory picker, defining discovery descriptors for BLE or Wi-Fi devices, handling accessory session events, migrating from CoreBluetooth permission-based scanning, or setting up accessories without requiring broad Bluetooth permissions./activitykitBuild or review Live Activities and Dynamic Island experiences with ActivityKit, including lifecycle, layouts, push updates, and scheduled delivery. Use for time-sensitive Lock Screen or Dynamic Island state; route ordinary widgets to widgetkit./adattributionkitMeasure ad effectiveness with privacy-preserving attribution using AdAttributionKit. Use when registering ad impressions, handling attribution postbacks, updating conversion values, implementing re-engagement attribution, configuring publisher or advertiser apps, or replacing SKAdNetwork with AdAttributionKit for ad measurement./all-ios-skills:swiftui-performancefrom all-ios-skills
npx claudepluginhub thienqo/ios-skills --plugin all-ios-skillsOther plugins' skills for the same job