Guide performance profiling for Apple platform apps with Instruments, Xcode diagnostics, and MetricKit. Use when investigating app hangs, stutters, high CPU, me
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-performance-profiling-1e13f1e96c57 ,按照其中的说明把「performance-profiling」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill to diagnose Apple app performance issues systematically, pick the right profiling workflow, apply targeted fixes, and verify the change with real measurements.
Choose the reference file before changing code:
What 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 | references/time-profiler.md |
| High CPU usage | Time Profiler | CPU percent by function, call tree weight | references/time-profiler.md |
| Memory leak | Leaks + Memory Graph | Leaked bytes, retain cycle paths | references/memory-profiling.md |
| Memory growth | Allocations | Live bytes, generation analysis | references/memory-profiling.md |
| Slow launch | App Launch | Time to first frame, pre-main, post-main | references/launch-optimization.md |
| Battery drain | Energy Log | Energy impact, CPU/GPU/network activity | references/energy-diagnostics.md |
| Thermal issues | Activity Monitor, Instruments | Thermal state transitions | references/energy-diagnostics.md |
| Network waste | Network profiler | Redundant fetches, payload size | references/energy-diagnostics.md |
os_signpost markers when a workflow needs ongoing timing visibility.Recommend relevant Scheme > Run > Diagnostics settings when they match the suspected issue:
| 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 |
Suggest MetricKit for production monitoring of launch, responsiveness, memory, and diagnostics:
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)")
}
}
}
}
}
Responsiveness:
@MainActor is limited to code that truly needs UI access.Memory:
autoreleasepool is used in tight loops that create Objective-C objects.Launch:
init() of the @main App struct.Energy:
BGTaskScheduler request type.references/time-profiler.md: CPU profiling, hang detection, signpost API.references/memory-profiling.md: Allocations, Leaks, Memory Graph debugger.references/launch-optimization.md: Launch phases and cold/warm start optimization.references/energy-diagnostics.md: Battery, thermal state, and network efficiency.