Ios performance audit
Skill almasumdev/awesome-ios-agent-skills/.github/skills/performance/ios-performance-audit
Expert guidance on auditing iOS runtime performance using Instruments (Time Profiler, Hangs, Allocations), SwiftUI view rebuild analysis, and common fix patterns. Use when the app feels slow or drops frames.From its SKILL.md
npx -y skills add almasumdev/awesome-ios-agent-skills --skill ios-performance-auditAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
5.4 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it
iOS Performance Audit
Instructions
Measure first, optimize second. Instruments and Xcode's built-in tooling pinpoint real hot paths so you don't rewrite code that isn't the problem.
1. Pick the Right Instrument
| Symptom | Instrument / Tool |
|---|---|
| Slow scrolling / jank | Time Profiler, Animation Hitches |
| UI freezes / spinning beachball | Hangs, Main Thread Checker |
| Memory growth | Allocations, Leaks |
| Excessive network traffic | Network |
| Battery / energy drain | Energy Log on device |
| Slow startup | App Launch (see ios-app-launch) |
| SwiftUI excessive rebuilds | _printChanges(), SwiftUI instrument |
Profile Release builds on a physical device — simulators lie.
2. Time Profiler Workflow
- Edit scheme → Profile action → Build Configuration: Release.
- Product → Profile (⌘I) → Time Profiler.
- Record the slow flow.
- In the call tree, enable Invert Call Tree, Hide System Libraries, Top Functions.
- Expand to the hottest user-code frame. That's the target.
Look for:
- Main-thread JSON decoding → move to a background
Taskor anactor. - Unnecessary work in
body→ extract, memoize, or move to model. Date/DateFormatterallocations in loops → cache formatters.Stringslicing / regex in tight loops → precompile.
3. Hangs
A hang is any main-thread block > 250 ms. Enable Hangs:
Debug → Debug Workflow → Always Show Disassembly (optional)
Product → Profile → Hangs
Typical causes: synchronous disk reads, Core Data fetches on the main context, JSON decoding, layout thrash. Move them off the main actor:
@MainActor
func onAppear() {
Task.detached(priority: .userInitiated) {
let articles = try await repository.latest()
await MainActor.run { self.articles = articles }
}
}
4. SwiftUI Rebuild Audit
Print what changes caused a re-evaluation of body:
struct ArticleList: View {
let articles: [Article]
var body: some View {
let _ = Self._printChanges()
ForEach(articles) { ArticleRow(article: $0) }
}
}
Common fixes:
- Pass values, not models, into child views.
- Split big views so state changes affect a small subtree.
- Make expensive views
Equatableand wrap inEquatableViewwhere needed. - Avoid reading unrelated
@Observableproperties inbody. - Replace
AnyViewwith concrete types.
5. List Performance
- Use
ListorLazyVStack— notForEachinsideVStackfor long content. - Ensure stable
id(preferIdentifiable). Avoid.id(UUID())reseeding. - Keep row views cheap: image decoding off-main,
.drawingGroup()only if profiled.
6. Image Pipeline
- Decode and resize to the target pixel size before drawing — don't hand a 4000×3000 image to a 60-point thumbnail view.
- Use
AsyncImagefor remote URLs; for custom flows, cacheUIImagein memory. - Consider
ImageRendererfor snapshot generation off-main.
func thumbnail(for data: Data, side: CGFloat, scale: CGFloat) async -> UIImage? {
await Task.detached(priority: .utility) {
let opts: [CFString: Any] = [
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceThumbnailMaxPixelSize: side * scale
]
guard let src = CGImageSourceCreateWithData(data as CFData, nil),
let cg = CGImageSourceCreateThumbnailAtIndex(src, 0, opts as CFDictionary)
else { return nil }
return UIImage(cgImage: cg, scale: scale, orientation: .up)
}.value
}
7. Memory
- Run Leaks and Allocations. Filter by your module.
- Watch for retain cycles:
[weak self]inTask { }is rarely needed (tasks end), but it matters in long-lived closures (Combine sinks, delegate blocks). - Use Memory Graph Debugger (Debug → Debug Memory Graph) to find cycles interactively.
8. Frame Rate & ProMotion
Target 120 Hz on ProMotion devices. Avoid animating views that force layout every frame. Prefer offset, opacity, scale transforms over size/frame animations on layout-heavy hierarchies.
9. Logging Hangs in Production
Use MetricKit to collect hang and launch metrics from real users:
import MetricKit
final class MetricsObserver: NSObject, MXMetricManagerSubscriber {
func didReceive(_ payloads: [MXMetricPayload]) { /* upload */ }
func didReceive(_ payloads: [MXDiagnosticPayload]) { /* hang traces */ }
}
Checklist
- All profiling is done on a physical device, Release build.
- Time Profiler trace saved for the slow flow with identified hot frame.
- No work > 16 ms on the main actor during scrolling.
- SwiftUI views pass
_printChangesreview for target screens. - Images are decoded/resized to target size before display.
- Memory graph shows no retain cycles in visited flows.
- MetricKit wired up for production hang / launch monitoring.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.