Performance Profiling
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.
When to use this skill
- App hangs, stutters, dropped frames, or high CPU usage on an Apple platform app that needs a Time Profiler pass
- Memory leaks, unbounded memory growth, or OOM crashes that need Leaks, Allocations, or the Memory Graph debugger
- Slow cold/warm launch or slow time to first frame that needs App Launch instrument analysis
- Battery drain, thermal throttling, or excess background/network energy use that needs an Energy Log pass
- Pre-release performance audits that need the full Xcode Diagnostics + MetricKit review checklist, or adding
os_signpost measurement hooks
- Not for general (non-Apple) web/service performance tuning such as bundle size, API latency, or database query plans — use
performance-optimization; not for Unity/Unreal engine frame-capture interpretation — use game-performance-profiler
Decision Tree
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
Quick Reference
| 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 |
Workflow
- Identify the performance category from the user report, traces, logs, or code path.
- Read only the matching reference file unless the issue is broad or unclear.
- Prefer real device profiling with a Release build and representative data.
- Inspect the code path named by the profile before proposing a fix.
- Apply the smallest targeted fix that addresses the measured bottleneck.
- Re-profile or add a repeatable measurement to confirm the improvement.
Profiling Ground Rules
- Profile on device when possible; Simulator uses host CPU and memory.
- Use Release configuration because optimizations can change hot paths.
- Reproduce with representative data, not empty databases or toy assets.
- Close unrelated apps to reduce noise during profiling.
- Keep measurements before and after the fix so the outcome is concrete.
- Add
os_signpost markers when a workflow needs ongoing timing visibility.
Xcode Diagnostics
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 |
MetricKit Hook
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)")
}
}
}
}
}
Review Checklist
Responsiveness:
- No synchronous work on the main thread over 100 ms.
- No file I/O or network calls on the main thread.
- Large Core Data or SwiftData fetches use background contexts.
- Images decode off the main thread.
@MainActor is limited to code that truly needs UI access.
Memory:
- No retain cycles in delegates, closures, observers, or async tasks.
- Large resources are released when no longer visible.
- Collections and caches are bounded.
autoreleasepool is used in tight loops that create Objective-C objects.
Launch:
- No heavy work in
init() of the @main App struct.
- Non-essential initialization is deferred.
- Dynamic frameworks are minimized where practical.
- No synchronous network calls occur during launch.
Energy:
- Background tasks use the appropriate
BGTaskScheduler request type.
- Location accuracy matches the product need.
- Timers use tolerance so the system can coalesce wakeups.
- Network requests are batched and cached where possible.
References
- Upstream source: MengTo/Skills — performance-profiling
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.
agents/openai.yaml: OpenAI agent interface metadata (display name, short description, default prompt).
1---2name: performance-profiling3description: >4 Guide performance profiling for Apple platform apps with Instruments, Xcode diagnostics, and5 MetricKit. Use when investigating app hangs, stutters, high CPU, memory leaks, memory growth,6 OOM crashes, slow launch, battery drain, thermal issues, App Store performance readiness, or7 when adding os_signpost and measurement hooks.8allowed-tools: Bash Read Write Edit Glob Grep WebFetch9compatibility: Authored for Codex CLI workflows; portable to any agent with filesystem and shell access. Some steps need the tool named in the skill body (browser capture, ffmpeg, Gmail, X/Twitter, ElevenLabs).10license: MIT11metadata:12 tags: performance, profiling, mengto-skills, codex-workflow13 version: "1.0"14 source: https://skillmd.com/skills/akillness/performance-profiling15 upstream: https://github.com/MengTo/Skills/tree/main/agent-skills/codex/performance-profiling16---1718# Performance Profiling1920Use this skill to diagnose Apple app performance issues systematically, pick the right profiling workflow, apply targeted fixes, and verify the change with real measurements.2122## When to use this skill2324- App hangs, stutters, dropped frames, or high CPU usage on an Apple platform app that needs a Time Profiler pass25- Memory leaks, unbounded memory growth, or OOM crashes that need Leaks, Allocations, or the Memory Graph debugger26- Slow cold/warm launch or slow time to first frame that needs App Launch instrument analysis27- Battery drain, thermal throttling, or excess background/network energy use that needs an Energy Log pass28- Pre-release performance audits that need the full Xcode Diagnostics + MetricKit review checklist, or adding `os_signpost` measurement hooks29- Not for general (non-Apple) web/service performance tuning such as bundle size, API latency, or database query plans — use `performance-optimization`; not for Unity/Unreal engine frame-capture interpretation — use `game-performance-profiler`303132## Decision Tree3334Choose the reference file before changing code:3536```text37What performance problem are you investigating?3839+ App hangs, stutters, dropped frames, slow UI, high CPU40 -> Read references/time-profiler.md4142+ High memory, leaks, OOM crashes, growing footprint43 -> Read references/memory-profiling.md4445+ Slow cold launch, warm launch, resume, or time to first frame46 -> Read references/launch-optimization.md4748+ Battery drain, thermal throttling, background energy, network waste49 -> Read references/energy-diagnostics.md5051+ General "app feels slow"52 -> Start with references/time-profiler.md, then references/memory-profiling.md5354+ Pre-release performance audit55 -> Read all reference files and use the review checklist below56```5758## Quick Reference5960| Problem | Instrument / Tool | Key Metric | Reference |61| --- | --- | --- | --- |62| UI hangs over 250 ms | Time Profiler + Hangs | Hang duration, main thread stack | `references/time-profiler.md` |63| High CPU usage | Time Profiler | CPU percent by function, call tree weight | `references/time-profiler.md` |64| Memory leak | Leaks + Memory Graph | Leaked bytes, retain cycle paths | `references/memory-profiling.md` |65| Memory growth | Allocations | Live bytes, generation analysis | `references/memory-profiling.md` |66| Slow launch | App Launch | Time to first frame, pre-main, post-main | `references/launch-optimization.md` |67| Battery drain | Energy Log | Energy impact, CPU/GPU/network activity | `references/energy-diagnostics.md` |68| Thermal issues | Activity Monitor, Instruments | Thermal state transitions | `references/energy-diagnostics.md` |69| Network waste | Network profiler | Redundant fetches, payload size | `references/energy-diagnostics.md` |7071## Workflow72731. Identify the performance category from the user report, traces, logs, or code path.742. Read only the matching reference file unless the issue is broad or unclear.753. Prefer real device profiling with a Release build and representative data.764. Inspect the code path named by the profile before proposing a fix.775. Apply the smallest targeted fix that addresses the measured bottleneck.786. Re-profile or add a repeatable measurement to confirm the improvement.7980## Profiling Ground Rules8182- Profile on device when possible; Simulator uses host CPU and memory.83- Use Release configuration because optimizations can change hot paths.84- Reproduce with representative data, not empty databases or toy assets.85- Close unrelated apps to reduce noise during profiling.86- Keep measurements before and after the fix so the outcome is concrete.87- Add `os_signpost` markers when a workflow needs ongoing timing visibility.8889## Xcode Diagnostics9091Recommend relevant Scheme > Run > Diagnostics settings when they match the suspected issue:9293| Setting | Use For |94| --- | --- |95| Main Thread Checker | UI work off the main thread |96| Thread Sanitizer | Data races and unsafe shared state |97| Address Sanitizer | Buffer overflows and use-after-free |98| Malloc Stack Logging | Allocation call stacks |99| Zombie Objects | Messages to deallocated objects |100101## MetricKit Hook102103Suggest MetricKit for production monitoring of launch, responsiveness, memory, and diagnostics:104105```swift106import MetricKit107108final class PerformanceReporter: NSObject, MXMetricManagerSubscriber {109 func startCollecting() {110 MXMetricManager.shared.add(self)111 }112113 func didReceive(_ payloads: [MXMetricPayload]) {114 for payload in payloads {115 if let launch = payload.applicationLaunchMetrics {116 log("Resume time: \(launch.histogrammedResumeTime)")117 }118 if let responsiveness = payload.applicationResponsivenessMetrics {119 log("Hang time: \(responsiveness.histogrammedApplicationHangTime)")120 }121 if let memory = payload.memoryMetrics {122 log("Peak memory: \(memory.peakMemoryUsage)")123 }124 }125 }126127 func didReceive(_ payloads: [MXDiagnosticPayload]) {128 for payload in payloads {129 if let hangs = payload.hangDiagnostics {130 for hang in hangs {131 log("Hang: \(hang.callStackTree)")132 }133 }134 }135 }136}137```138139## Review Checklist140141Responsiveness:142- No synchronous work on the main thread over 100 ms.143- No file I/O or network calls on the main thread.144- Large Core Data or SwiftData fetches use background contexts.145- Images decode off the main thread.146- `@MainActor` is limited to code that truly needs UI access.147148Memory:149- No retain cycles in delegates, closures, observers, or async tasks.150- Large resources are released when no longer visible.151- Collections and caches are bounded.152- `autoreleasepool` is used in tight loops that create Objective-C objects.153154Launch:155- No heavy work in `init()` of the `@main App` struct.156- Non-essential initialization is deferred.157- Dynamic frameworks are minimized where practical.158- No synchronous network calls occur during launch.159160Energy:161- Background tasks use the appropriate `BGTaskScheduler` request type.162- Location accuracy matches the product need.163- Timers use tolerance so the system can coalesce wakeups.164- Network requests are batched and cached where possible.165166## References167168- [Upstream source: MengTo/Skills — performance-profiling](https://github.com/MengTo/Skills/tree/main/agent-skills/codex/performance-profiling)169- `references/time-profiler.md`: CPU profiling, hang detection, signpost API.170- `references/memory-profiling.md`: Allocations, Leaks, Memory Graph debugger.171- `references/launch-optimization.md`: Launch phases and cold/warm start optimization.172- `references/energy-diagnostics.md`: Battery, thermal state, and network efficiency.173- `agents/openai.yaml`: OpenAI agent interface metadata (display name, short description, default prompt).