swiftui-debugging
БесплатноБез исполняемых скриптовНе проверенDiagnose SwiftUI performance issues including unnecessary re-renders, view identity problems, and slow body evaluations. Use when SwiftUI views are slow…
от rshankras★ 922 звезды на GitHubОб этом скилле
SwiftUI Performance Debugging
Systematic guide for diagnosing and fixing SwiftUI performance problems: unnecessary view re-evaluations, identity issues, expensive body computations, and lazy loading mistakes.
When This Skill Activates
Use this skill when the user:
- Reports slow or janky SwiftUI views
- Sees excessive view re-renders or body re-evaluations
- Asks about
Self._printChanges()or view debugging - Has scrolling performance issues with lists or grids
- Asks why a view keeps updating when nothing changed
- Mentions
@ObservableorObservableObjectperformance differences - Wants to understand SwiftUI view identity or diffing
- Uses
AnyViewand asks about performance implications - Has a hang or stutter traced to SwiftUI rendering
The Performance Loop
Every investigation follows the same loop: symptom -> measure -> identify -> optimize -> RE-MEASURE. The last step is the one people skip -- an "optimization" that was never re-measured is a guess, and SwiftUI guesses are wrong often enough (a fix can shift cost elsewhere) that the loop is not optional. Never close a performance issue on the strength of the diff alone.
Decision Tree
What SwiftUI performance problem are you seeing?
|
+- Views re-render when they should not
| +- Read body-reevaluation.md
| +- Self._printChanges() to identify which property changed
| +- @Observable vs ObservableObject observation differences
| +- Splitting views to narrow observation scope
|
+- Scrolling is slow / choppy (lists, grids)
| +- Read lazy-loading.md
| +- VStack vs LazyVStack, ForEach without lazy container
| +- List prefetching, grid cell reuse
|
+- Views lose state unexpectedly / animate when they should not
| +- Read view-identity.md
| +- Structural vs explicit identity
| +- .id() misuse, conditional view branching
|
+- Known pitfall (AnyView, DateFormatter in body, etc.)
| +- Read common-pitfalls.md
| +- AnyView type erasure, object creation in body
| +- Over-observation, expensive computations
|
+- General "my SwiftUI app is slow" (unknown cause)
| +- Start with body-reevaluation.md, then common-pitfalls.md
| +- Use Instruments SwiftUI template (see Debugging Tools below)
API Availability
| API / Technique | Minimum Version | Reference |
|---|---|---|
Self._printChanges() |
iOS 15 | body-reevaluation.md |
@Observable |
iOS 17 / macOS 14 | body-reevaluation.md |
@ObservableObject |
iOS 13 | body-reevaluation.md |
LazyVStack / LazyHStack |
iOS 14 | lazy-loading.md |
LazyVGrid / LazyHGrid |
iOS 14 | lazy-loading.md |
.id() modifier |
iOS 13 | view-identity.md |
| Instruments SwiftUI template | Xcode 14+ | SKILL.md |
| Redesigned SwiftUI instrument | Xcode 26 / Instruments 26 | SKILL.md |
os_signpost |
iOS 12 | SKILL.md |
Top 5 Mistakes -- Quick Reference
| # | Mistake | Fix | Details |
|---|---|---|---|
| 1 | Large ForEach inside VStack or ScrollView without lazy container |
Wrap in LazyVStack -- eager VStack creates all views upfront |
lazy-loading.md |
| 2 | Using AnyView to erase types |
Use @ViewBuilder, Group, or concrete generic types -- AnyView defeats diffing |
common-pitfalls.md |
| 3 | Creating objects in body (DateFormatter(), NumberFormatter()) |
Use static let shared instances or @State for mutable objects |
common-pitfalls.md |
| 4 | Observing entire model when only one property is needed | Split into smaller @Observable objects or extract subviews |
body-reevaluation.md |
| 5 | Unstable .id() values causing full view recreation every render |
Use stable identifiers (database IDs, UUIDs), never array indices or random values | view-identity.md |
Lists, Tables, and ForEach: Identity Is the Cost Model
List and Table gather all identifiers eagerly at load -- even though row views are lazy. Cheap, precomputed IDs mean fast loads; an id: key path that computes or hashes something expensive runs for every element before anything renders.
The row-count equation: rows = elements x views-per-element, and views-per-element must be a constant the framework can read without executing your closures.
- ❌ No
iffilters and noAnyViewinsideForEach-- both make views-per-element non-constant, forcing SwiftUI to run every closure just to count rows (and defeatingList's constant-count optimizations). - ✅ Filter in the data, not the view -- and cache the filtered collection in the model: an inline
items.filter { ... }inbodyre-runs linearly on every single body evaluation. - ✅ For
Table, prefer the streamlinedForEach(collection)initializer (noid:, no per-row closure gymnastics) -- it keeps row counts statically constant.
Common Slow-Update Causes
When a body or update shows up slow in the profile, it is almost always one of these:
- Expensive dynamic-property initialization -- e.g. a
@StateObject/
Установить swiftui-debugging в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGlobGrepВложенные файлы
FAQ
Что делает скилл swiftui-debugging?
Diagnose SwiftUI performance issues including unnecessary re-renders, view identity problems, and slow body evaluations. Use when SwiftUI views are slow, janky, or re-rendering too often.
Как установить скилл swiftui-debugging?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл swiftui-debugging запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic