$npx -y skills add One-Man-Company/Skills-ContextManager --skill performance-profilingPerformance profiling principles. Measurement, analysis, and optimization techniques.
| 1 | # Performance Profiling |
| 2 | |
| 3 | > Measure, analyze, optimize - in that order. |
| 4 | |
| 5 | ## 🔧 Runtime Scripts |
| 6 | |
| 7 | **Execute these for automated profiling:** |
| 8 | |
| 9 | | Script | Purpose | Usage | |
| 10 | |--------|---------|-------| |
| 11 | | `scripts/lighthouse_audit.py` | Lighthouse performance audit | `python scripts/lighthouse_audit.py https://example.com` | |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## 1. Core Web Vitals |
| 16 | |
| 17 | ### Targets |
| 18 | |
| 19 | | Metric | Good | Poor | Measures | |
| 20 | |--------|------|------|----------| |
| 21 | | **LCP** | < 2.5s | > 4.0s | Loading | |
| 22 | | **INP** | < 200ms | > 500ms | Interactivity | |
| 23 | | **CLS** | < 0.1 | > 0.25 | Stability | |
| 24 | |
| 25 | ### When to Measure |
| 26 | |
| 27 | | Stage | Tool | |
| 28 | |-------|------| |
| 29 | | Development | Local Lighthouse | |
| 30 | | CI/CD | Lighthouse CI | |
| 31 | | Production | RUM (Real User Monitoring) | |
| 32 | |
| 33 | --- |
| 34 | |
| 35 | ## 2. Profiling Workflow |
| 36 | |
| 37 | ### The 4-Step Process |
| 38 | |
| 39 | ``` |
| 40 | 1. BASELINE → Measure current state |
| 41 | 2. IDENTIFY → Find the bottleneck |
| 42 | 3. FIX → Make targeted change |
| 43 | 4. VALIDATE → Confirm improvement |
| 44 | ``` |
| 45 | |
| 46 | ### Profiling Tool Selection |
| 47 | |
| 48 | | Problem | Tool | |
| 49 | |---------|------| |
| 50 | | Page load | Lighthouse | |
| 51 | | Bundle size | Bundle analyzer | |
| 52 | | Runtime | DevTools Performance | |
| 53 | | Memory | DevTools Memory | |
| 54 | | Network | DevTools Network | |
| 55 | |
| 56 | --- |
| 57 | |
| 58 | ## 3. Bundle Analysis |
| 59 | |
| 60 | ### What to Look For |
| 61 | |
| 62 | | Issue | Indicator | |
| 63 | |-------|-----------| |
| 64 | | Large dependencies | Top of bundle | |
| 65 | | Duplicate code | Multiple chunks | |
| 66 | | Unused code | Low coverage | |
| 67 | | Missing splits | Single large chunk | |
| 68 | |
| 69 | ### Optimization Actions |
| 70 | |
| 71 | | Finding | Action | |
| 72 | |---------|--------| |
| 73 | | Big library | Import specific modules | |
| 74 | | Duplicate deps | Dedupe, update versions | |
| 75 | | Route in main | Code split | |
| 76 | | Unused exports | Tree shake | |
| 77 | |
| 78 | --- |
| 79 | |
| 80 | ## 4. Runtime Profiling |
| 81 | |
| 82 | ### Performance Tab Analysis |
| 83 | |
| 84 | | Pattern | Meaning | |
| 85 | |---------|---------| |
| 86 | | Long tasks (>50ms) | UI blocking | |
| 87 | | Many small tasks | Possible batching opportunity | |
| 88 | | Layout/paint | Rendering bottleneck | |
| 89 | | Script | JavaScript execution | |
| 90 | |
| 91 | ### Memory Tab Analysis |
| 92 | |
| 93 | | Pattern | Meaning | |
| 94 | |---------|---------| |
| 95 | | Growing heap | Possible leak | |
| 96 | | Large retained | Check references | |
| 97 | | Detached DOM | Not cleaned up | |
| 98 | |
| 99 | --- |
| 100 | |
| 101 | ## 5. Common Bottlenecks |
| 102 | |
| 103 | ### By Symptom |
| 104 | |
| 105 | | Symptom | Likely Cause | |
| 106 | |---------|--------------| |
| 107 | | Slow initial load | Large JS, render blocking | |
| 108 | | Slow interactions | Heavy event handlers | |
| 109 | | Jank during scroll | Layout thrashing | |
| 110 | | Growing memory | Leaks, retained refs | |
| 111 | |
| 112 | --- |
| 113 | |
| 114 | ## 6. Quick Win Priorities |
| 115 | |
| 116 | | Priority | Action | Impact | |
| 117 | |----------|--------|--------| |
| 118 | | 1 | Enable compression | High | |
| 119 | | 2 | Lazy load images | High | |
| 120 | | 3 | Code split routes | High | |
| 121 | | 4 | Cache static assets | Medium | |
| 122 | | 5 | Optimize images | Medium | |
| 123 | |
| 124 | --- |
| 125 | |
| 126 | ## 7. Anti-Patterns |
| 127 | |
| 128 | | ❌ Don't | ✅ Do | |
| 129 | |----------|-------| |
| 130 | | Guess at problems | Profile first | |
| 131 | | Micro-optimize | Fix biggest issue | |
| 132 | | Optimize early | Optimize when needed | |
| 133 | | Ignore real users | Use RUM data | |
| 134 | |
| 135 | --- |
| 136 | |
| 137 | > **Remember:** The fastest code is code that doesn't run. Remove before optimizing. |