# Performance

> Measure and improve speed against a budget (latency, p95, p99, throughput, memory use or a memory leak, CPU, startup time, page load, bundle size, Core Web Vita

- Skill: `ilexpwh/performance` (Agent Skill)
- Install (CLI): `npx get-skill add ilexpwh/performance`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ilexpwh/performance/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: Ilexpwh (https://skillmd.com/u/ilexpwh)
- Updated: 2026-12-02
- Page: https://skillmd.com/skills/ilexpwh/performance

---

---
name: performance
description: Measure and improve speed against a budget (latency, p95, p99, throughput, memory use or a memory leak, CPU, startup time, page load, bundle size, Core Web Vitals) with baseline and after numbers you can explain. Use when something is slow or got slower, or the user says benchmark, run a benchmark of old against new, profile, profiler, flame graph, optimise, optimize, make it faster, perf, performance budget or perf regression. Not for errors or wrong output (diagnose).
metadata:
  phase: review
---

# Performance

A change measured against a budget, with baseline and treatment numbers, their spread, and the limiter that explains them, kept or reverted on the numbers and recorded as evidence.

## When to use
- The charter sets a budget (p95 latency, throughput, memory, bundle size, startup, Core Web Vitals) and a change touches that path.
- Something is slow, or a change may have made it slower.
- The user asks to benchmark, profile or optimise.

**Not for:** errors, crashes or wrong output (`diagnose`), or a non-speed claim on the target (`prove-it-live`).

## Steps
1. **Write the budget and the claim.** Take the budget from the charter. If there is none, propose one number with a reason, record it with `decide`, and proceed on it. Write the sentence you expect to ship: "p95 of `GET /search` on staging under 300 ms at 50 requests per second". *Done when:* metric, statistic, workload, environment and threshold are written down.
2. **Read the measurement before trusting it.** Open the benchmark or load script: what is inside the timed region, what is outside, and how errors are counted. Check the machine is quiet and that both sides will run on the same machine, build mode and data. Work through `references/benchmark-checklist.md`. *Done when:* you can say what one sample is and what the timed region contains.
3. **Measure the baseline.** Warm up, then run at least five repeats on the unchanged code. Record the median, the spread (min–max) and the error count. *Done when:* the baseline has a number, a unit, a run count, a spread and no unexplained errors.
4. **Profile to find the limiter.** In a separate run, because profilers slow the work, capture the fitting artifact: CPU profile or flame graph, request trace, query plan (`EXPLAIN ANALYZE`), heap snapshot, or bundle report. Name the one thing that bounds the number: a hot function, a query, a lock, a round trip, a disk or network ceiling, or the load generator itself. *Done when:* the limiter is named with the artifact that shows it, not guessed from reading code.
5. **Change one thing.** Try the cheapest lever first: drop work whose result nobody uses; do it once instead of repeatedly; do less of it; do it later or off the hot path; do it concurrently; only then make it cheaper. One change per measurement (`smallest-change`). *Done when:* the diff holds one optimisation and the tests still pass.
6. **Re-measure the same way.** Same command, machine, data, warm-up and repeat count. Alternate baseline and treatment runs (A, B, A, B) when the machine is noisy. *Done when:* the treatment has the same statistics as the baseline.
7. **Explain the number, then keep or revert.** Check that the work really ran, that no errors made it look fast, that the gain fits the physical limits and the share of time the changed piece had, and that the delta is larger than the spread. Keep the change only if it moves toward the budget past the noise with tests green. Revert neutral or worse changes and record them as dead ends. *Done when:* every attempt is marked kept or reverted with its numbers.
8. **Record it.** Copy `../istack-mode/templates/evidence.md` to the ledger's `run/evidence/<id>-perf.md`: the budget as the claim, baseline, treatment, run count, spread, limiter, and every attempt including reverted ones. Record a kept trade-off (memory for speed, staleness for load) with `decide`. Put one headline number in the PR body and link the file. Checking the budget on the running target goes through `prove-it-live`. *Done when:* the evidence file exists and the tracker row links it.

## Red flags
| If you're thinking | Do this instead |
|---|---|
| "This loop looks slow; I'll rewrite it." | Measure first. Optimise only what a profile names. |
| "It's 4% faster." | Compare it with the spread. Inside run-to-run variation, it is no difference. |
| "I'll ship these three tweaks together." | One change per measurement, or you can't say which one helped. |
| "Baseline yesterday on my laptop, treatment today on CI." | Same machine, build mode, data and session for both sides. |
| "The micro-benchmark is ten times faster." | Report its share of the end-to-end path the user waits on. |
| "No measurable change, but it's harmless; keep it." | Neutral is a revert. Unmeasured complexity is a cost. |
| "Requests got much faster." | Count errors and check outputs first. Fast failures look like speed. |
| "Debug build against release build is close enough." | Run both sides the way production runs. |

## Verify
- [ ] The budget and the claim were written before the first measurement.
- [ ] Baseline and treatment share machine, build, data and warm-up, with at least five repeats each and the spread reported.
- [ ] The limiter is named from a profile or counter, not from reading code.
- [ ] Every attempt is kept or reverted with numbers; neutral ones were reverted.
- [ ] The evidence file is under `run/evidence/` and linked from the tracker row.

## Reply
```
<within budget | over budget | no measurable change | inconclusive>: <metric> <baseline> → <treatment> (<delta>), budget <threshold>.
Runs: <n> per side, spread <min–max>, on <machine and build>. Limiter: <what bounds it>.
Attempts: <change → kept | reverted, numbers>.
Evidence: <path>. Next: <prove-it-live on the target | another attempt | blocked: exact command>.
```

## Credits
Measure, identify, fix, re-measure, "neutral is a revert" and logging reverted attempts come from Addy Osmani's `performance-optimization` in addyosmani/agent-skills. The limiter question, the checklist in `references/benchmark-checklist.md` and the ordered list of cheaper levers follow pstack's `benchmark-checklist`, `principle-explain-the-number` and `perf-issue` playbook by Lauren Tan; the levers echo widely shared performance mantras.

