一键导入
swift-performance-pro
Use when diagnosing or fixing performance — SwiftUI render cost, memory and retain cycles, slow lists, launch time, and using Instruments.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when diagnosing or fixing performance — SwiftUI render cost, memory and retain cycles, slow lists, launch time, and using Instruments.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when writing, reviewing, or refactoring SwiftUI code — covers modern state management (@Observable), NavigationStack, layout, performance, and accessibility for iOS 26 / Swift 6.
Use when adding App Intents — exposing app actions to Siri, Shortcuts, and Spotlight with AppIntent, parameters, AppEntity, and App Shortcuts.
Use when working with Core Data — modeling entities, NSPersistentContainer setup, background contexts, fetch requests, batch operations, and migrations.
Use when making SwiftUI/UIKit apps accessible — VoiceOver labels and traits, Dynamic Type, color contrast, Reduce Motion, and accessibility testing.
Use when structuring an iOS app — feature modularization, MVVM with @Observable, dependency injection, navigation routing, and layering for testability.
Use when writing or reviewing core Swift — choosing value vs reference types, handling optionals, error handling, generics, protocols, and following Swift API design guidelines.
| name | swift-performance-pro |
| description | Use when diagnosing or fixing performance — SwiftUI render cost, memory and retain cycles, slow lists, launch time, and using Instruments. |
| license | MIT |
| metadata | {"author":"Lax Rajpurohit","version":"1.0.0"} |
Find and fix performance problems with evidence, not guesses. Measure first.
Trigger: /swift-performance-pro.
body cheap and pure; recomputation is frequent.Keep body free of side effects and heavy compute.
❌ Sorting on every render
var body: some View {
List(items.sorted { $0.date > $1.date }) { Row($0) } // re-sorts each pass
}
✅ Sort once in the model
// model exposes already-sorted `items`
var body: some View { List(model.items) { Row($0) } }
Narrow observation so unrelated changes don't redraw everything. Split big views into small subviews so SwiftUI can diff precisely.
LazyVStack/List for long content, not eager VStack in a ScrollView.Identifiable IDs — index-based identity forces full rebuilds.AnyView in row builders; it defeats SwiftUI's diffing.❌ Strong self capture in a stored closure
manager.onUpdate = { self.refresh() } // cycle: manager → closure → self
✅
manager.onUpdate = { [weak self] in self?.refresh() }
Verify deinit runs. Use Instruments → Leaks / Allocations to confirm.
❌
let image = UIImage(data: hugeData) // decode on main → dropped frames
✅
let image = await Task.detached { UIImage(data: hugeData) }.value
Downsample large images to the display size instead of loading full-resolution.
init/onAppear; load it in .task.body.VStack where LazyVStack/List is needed.AnyView in hot row builders.self in stored closures (retain cycle).Per issue: file:line, the cost, before/after, and which Instrument confirms it. Lead with main-thread blockers.