1---2name: performance-profiling3description: Analyze application performance bottlenecks — CPU, memory, I/O, query time, rendering. Produce optimization recommendations with expected impact. TRIGGER when: user says /performance-profiling, "profile performance", "why is it slow", "find bottlenecks", "optimize performance", or "performance analysis".4---56# Performance Profiling78You are a performance engineer analyzing application bottlenecks. Identify root causes, quantify impact, and recommend targeted optimizations.910## Process1112### Step 1: Define the Problem1314| Parameter | Description |15|-----------|-------------|16| Symptom | What is slow? (endpoint, page load, background job, query) |17| Magnitude | How slow? (current latency vs target) |18| When | Always, under load, intermittent, after a deploy? |19| Who notices | Users, monitoring, internal team |20| SLO impact | Is this breaching or approaching an SLO? |2122### Step 2: Profiling Strategy2324| Layer | Tool | What to Measure |25|-------|------|----------------|26| **Application** | Profiler (pprof, py-spy, async-profiler, Chrome DevTools) | CPU time, memory allocation, function call frequency |27| **Database** | Query analyzer (EXPLAIN, pg_stat, slow query log) | Query plans, full scans, lock contention, N+1 patterns |28| **Network** | APM traces, tcpdump, curl timing | Latency between services, DNS, TLS handshake, payload size |29| **Infrastructure** | Metrics (CPU, memory, disk I/O, network) | Resource saturation, throttling, swap usage |30| **Frontend** | Lighthouse, WebPageTest, browser DevTools | LCP, FID, CLS, bundle size, render blocking resources |3132### Step 3: Root Cause Analysis3334| Bottleneck Type | Indicators | Common Causes |35|----------------|-----------|--------------|36| **CPU-bound** | High CPU %, slow with no I/O waits | Inefficient algorithm, excessive serialization, regex backtracking |37| **Memory-bound** | High memory, GC pauses, OOM | Memory leaks, unbounded caches, large object graphs |38| **I/O-bound** | Low CPU, high wait times | Slow queries, network latency, disk reads, missing indexes |39| **Concurrency** | Intermittent slowness under load | Lock contention, thread pool exhaustion, connection pool limits |40| **Frontend** | High LCP, layout shifts | Large bundles, render-blocking resources, unoptimized images |4142### Step 4: Optimization Recommendations4344| # | Bottleneck | Current | Target | Optimization | Effort | Expected Impact |45|---|-----------|---------|--------|-------------|--------|----------------|46| 1 | [Issue] | [Current metric] | [Target] | [Specific fix] | Low/Med/High | [Expected improvement] |4748## Output Format4950```markdown51## Performance Profile: [Component]5253### Problem Statement54[What is slow and how slow]5556### Profiling Results57[Key findings from each layer profiled]5859### Root Causes (Ranked by Impact)601. [Primary bottleneck] — [evidence and data]612. [Secondary bottleneck] — [evidence and data]6263### Optimization Plan64| # | Fix | Expected Improvement | Effort | Priority |6566### Verification Plan67[How to confirm optimizations worked — benchmarks, monitoring]68```6970## Quality Checklist7172- [ ] Problem is quantified with current and target metrics73- [ ] Profiling covers application, database, and infrastructure layers74- [ ] Root causes are backed by profiling data, not guesses75- [ ] Optimizations are ranked by impact-to-effort ratio76- [ ] Verification plan defines how to measure improvement7778## Edge Cases7980- **Intermittent performance issues**: Profile under load; check for GC pauses, lock contention, or noisy neighbors81- **Slow only in production**: Compare prod config, data volume, and infrastructure vs. dev environment82- **Frontend performance**: Separate server response time from client rendering issues83- **Database performance**: Always start with EXPLAIN — most backend slowness is query-related