Loading...
Loading...
Guide performance profiling for Apple platform apps with Instruments, Xcode diagnostics, and MetricKit. Use when investigating app hangs, stutters, high CPU, memory leaks, memory growth, OOM crashes, slow launch, battery drain, thermal issues, App Store performance readiness, or when adding os_signpost and measurement hooks.
npx skill4agent add mengto/skills performance-profilingWhat performance problem are you investigating?
+ App hangs, stutters, dropped frames, slow UI, high CPU
-> Read references/time-profiler.md
+ High memory, leaks, OOM crashes, growing footprint
-> Read references/memory-profiling.md
+ Slow cold launch, warm launch, resume, or time to first frame
-> Read references/launch-optimization.md
+ Battery drain, thermal throttling, background energy, network waste
-> Read references/energy-diagnostics.md
+ General "app feels slow"
-> Start with references/time-profiler.md, then references/memory-profiling.md
+ Pre-release performance audit
-> Read all reference files and use the review checklist below| Problem | Instrument / Tool | Key Metric | Reference |
|---|---|---|---|
| UI hangs over 250 ms | Time Profiler + Hangs | Hang duration, main thread stack | |
| High CPU usage | Time Profiler | CPU percent by function, call tree weight | |
| Memory leak | Leaks + Memory Graph | Leaked bytes, retain cycle paths | |
| Memory growth | Allocations | Live bytes, generation analysis | |
| Slow launch | App Launch | Time to first frame, pre-main, post-main | |
| Battery drain | Energy Log | Energy impact, CPU/GPU/network activity | |
| Thermal issues | Activity Monitor, Instruments | Thermal state transitions | |
| Network waste | Network profiler | Redundant fetches, payload size | |
os_signpost| Setting | Use For |
|---|---|
| Main Thread Checker | UI work off the main thread |
| Thread Sanitizer | Data races and unsafe shared state |
| Address Sanitizer | Buffer overflows and use-after-free |
| Malloc Stack Logging | Allocation call stacks |
| Zombie Objects | Messages to deallocated objects |
import MetricKit
final class PerformanceReporter: NSObject, MXMetricManagerSubscriber {
func startCollecting() {
MXMetricManager.shared.add(self)
}
func didReceive(_ payloads: [MXMetricPayload]) {
for payload in payloads {
if let launch = payload.applicationLaunchMetrics {
log("Resume time: \(launch.histogrammedResumeTime)")
}
if let responsiveness = payload.applicationResponsivenessMetrics {
log("Hang time: \(responsiveness.histogrammedApplicationHangTime)")
}
if let memory = payload.memoryMetrics {
log("Peak memory: \(memory.peakMemoryUsage)")
}
}
}
func didReceive(_ payloads: [MXDiagnosticPayload]) {
for payload in payloads {
if let hangs = payload.hangDiagnostics {
for hang in hangs {
log("Hang: \(hang.callStackTree)")
}
}
}
}
}@MainActorautoreleasepoolinit()@main AppBGTaskSchedulerreferences/time-profiler.mdreferences/memory-profiling.mdreferences/launch-optimization.mdreferences/energy-diagnostics.md