swiftui-performance-audit
БесплатноБез исполняемых скриптовНе проверенFinds out why a SwiftUI screen is slow and what to change: classifies the symptom as a hang, a hitch or excessive updates, audits the code for the usual…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
SwiftUI Performance Audit
Overview
SwiftUI is slow in two ways. Either one update takes too long (a body, a layout pass or an image decode that does not fit in a frame), or there are too many updates (views recomputed because something they depend on changed, although nothing they show did). Both end as work on the main thread, and the person sees a frozen control or stuttering motion. An audit names which of the two is happening, on which view, caused by which dependency or call, and proves the fix with the same measurement taken before and after. Guessing from code alone is allowed as a first pass, but it must be labelled as a hypothesis until a trace confirms it.
Instructions
1. Name the symptom and the conditions
Ask for, or find in the report: the exact interaction (for example "typing in the search field on Orders"), device model and OS version, build configuration, how much data is on screen, and whether it was always slow or regressed.
| What the person sees | Term | Numbers to hold on to | First tool |
|---|---|---|---|
| A tap, keystroke or screen opening responds late | Hang: the main run loop is busy | Under 100 ms is rarely noticed; Apple's tools start reporting at 250 ms | Hangs instrument with Time Profiler |
| Scrolling or animation stutters | Hitch: a frame arrived late | A frame has 16.7 ms at 60 Hz and 8.3 ms at 120 Hz. Organizer hitch rate: up to 10 ms/s good, up to 25 warning, up to 50 critical | Hitches instrument, SwiftUI instrument |
| CPU busy or battery drain while nothing seems to change | Excess updates | Count of body updates per interaction | SwiftUI instrument, Update Groups lane |
| Memory climbs while scrolling | Usually full-size images | Peak memory before and after | Allocations template |
A hitch caused by the app's main thread missing its deadline is a commit hitch; one caused by a frame that is too expensive to draw (many layers, blurs, shadows, glass) is a render hitch. They have different fixes, so note which one the Hitches instrument reports.
2. Audit the code for the usual causes
Read the slow view, the views it contains, and the model types it reads. Check each of these and cite the line when you find one.
| Cause | What it looks like in code | Fix |
|---|---|---|
Work inside body |
Sorting, filtering, grouping, string formatting, creating a DateFormatter or NumberFormatter, reading files, decoding images in body, in a view init, or in onAppear |
Compute once in the model when inputs change; store the result; format with formatted() styles or a shared formatter |
| Dependencies wider than needed | An ObservableObject with many @Published properties observed by many views; a whole model passed to a row that shows two fields; frequently changing values (scroll offset, timers, geometry) placed in the environment |
Adopt @Observable (iOS 17+), which only invalidates views whose body read the changed property; pass plain values to leaf views; keep fast-changing values out of the environment |
| Unstable identity | ForEach(items, id: \.self) on values that are not unique or are expensive to hash; ids made from array indices for data that reorders; .id(UUID()); if/else that swaps whole subtrees; AnyView |
Identifiable with a stable id from the data; keep one view and vary its modifiers |
| Variable row count per element | An if inside ForEach content that sometimes yields no view |
Filter the collection before ForEach, so List can count rows without building them |
| Eager containers | VStack or HStack in a ScrollView with hundreds of children |
List, LazyVStack, LazyVGrid, after profiling shows the load cost |
| Layout feedback | GeometryReader around large content; onGeometryChange or scroll callbacks writing state every frame |
Update state only when the value crosses a threshold; move the dependent view into a small sibling |
| Stored closures | A view storing an escaping @ViewBuilder closure that captures the parent's state |
Call the builder in init and store the resulting view |
| Images | Photos decoded at full size for small cells; decoding on the main thread | byPreparingThumbnail(ofSize:) or preparingThumbnail(of:) off the main actor, sized in pixels |
| Expensive rendering | Blur, shadow or glass on every cell; animating a large container | Apply effects to one parent; animate with animation(_:value:) on the smallest view that changes |
To see why one view's body runs, add let _ = Self._printChanges() as the first line of body in a debug build. It prints which property changed, or that the view value itself did. The underscore means it is a debugging aid that may disappear, and Apple says never to ship a call to it. Remove it before committing.
3. Get a measurement
Code review produces suspects. A trace turns them into findings. Ask the user to record this (the agent cannot drive Instruments):
- Use a physical device, not the simulator, and the Pr
Установить swiftui-performance-audit в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл swiftui-performance-audit?
Finds out why a SwiftUI screen is slow and what to change: classifies the symptom as a hang, a hitch or excessive updates, audits the code for the usual causes, reads Instruments evidence (the SwiftUI instrument, Time Profiler, Hangs, Hitches), proposes targeted fixes and checks them with a second measurement. Use when the user says "my list scrolls badly", "typing lags in this view", "the app freezes when I open this screen", "why does this view re-render so often", "audit this SwiftUI code for performance", or shares an Instruments trace or screenshots of one.
Как установить скилл swiftui-performance-audit?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл swiftui-performance-audit запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic