/profile-skills:perf-optimizefrom Profile Skills
Make code measurably faster or leaner without breaking it - the recursive loop of baseline → profile → one hypothesis → one change → re-measure with statistics → keep only if significant AND tests stay green, otherwise revert and record why, repeat until a stop rule fires - for Python, JavaScript/TypeScript on Node and Bun, browser pages and Bash. Pins behaviour first (tests and coverage of the changed path, kill matrix at higher rigor), records every experiment (kept or rejected) in Quest and lore, hands concurrency and algorithm-equivalence questions to proof-skills, and scales evidence with the R1-R5 rigor profiles. Use this skill whenever the user asks to speed something up, optimize, reduce latency/memory/startup/build time/bundle size/page load, says something is "slow", "takes forever", "times out" or "uses too much memory", wants a performance pass, or asks to iteratively/recursively improve performance - even if they never say "profile". For measuring or reviewing without changing code use perf-measure; for CI gates use perf-ci.
Ships in Profile Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Agents fail at performance work in specific, well-measured ways:
What works is a profiler in the loop: PerfAgent doubled expert-matching rates with it. That needs a trustworthy evaluator and correctness as a hard gate. This skill is that loop, with explicit rules.
Measurement, profiling and the decision rule come from perf-measure:
PK=${CLAUDE_SKILL_DIR}/../perf-measure/scripts/perfkit.py. Read perf-measure's SKILL.md
"Rules that apply in every mode" once before starting.
test-policy.toml default and the tier of every
path you will touch, perf-policy.toml tiers, anything the user declared). Raise it for
money, auth, data integrity or shared hot paths; never lower it. State it in your first
message. What each level demands: references/rigor.md.quest search, then quest task create), and put the scope in its description.
Artefacts go in .perf/<concern>/, which must be git-ignored. Each experiment is appended
to the task with perfkit ledger add --quest-task <id>. The final report becomes a lore
Reference. Details: references/records.md.python3 $PK doctor. Fix what you can (AC power, close heavy apps,
install the tool you need per ADR-0006), and carry the remaining warnings into the report.Scope. Before touching code, write in .perf/<concern>/SCOPE.md and the task:
Pin behaviour first. A speedup that changes behaviour is a bug.
coverage run -m pytest /
c8 / bun test --coverage, then coverage report --include=<files>..perf/<concern>/ that diffs old vs new outputs on the workload plus randomized and
edge inputs.tmx collect-pytest, or a Stryker import for JS) before the change. Its kills must
survive afterwards.references/guards.md).Baseline. Interleaved A/B of the current code against itself (perfkit abtest, ≥10
runs per arm at R3). This measures noise and gives the minimum detectable effect for
the session. Record median, IQR, MDE and environment.
Profile the same workload with perf-measure's profile mode, and save the hotspot table.
One hypothesis. Name the frame, its share, its Amdahl ceiling, the mechanism and a
predicted gain. Walk the ladder top-down (references/ladder.md):
do less work → algorithm/data structure → batch I/O → concurrency → caching →
runtime/native → micro-tuning. Skip any hypothesis whose ceiling is below the MDE.
One change. Change exactly one thing, then run the tests and the equivalence harness. A failure is a revert.
Re-measure the candidate against the incumbent (the last kept state, in a worktree
at .perf/wt-incumbent), interleaved and paired, with --require-same-output. Then run
perfkit compare. This is ADR-0005's rule; nothing else decides.
Keep or revert:
| Outcome | Action |
|---|---|
verdict improved and tests and harness green and no secondary metric regressed beyond its tolerance | keep: commit perf(<concern>): E<n> …, advance the incumbent |
verdict equivalent/below-threshold and the code is clearly simpler | keep as kept-simplification, and say what got simpler |
| anything else | revert (git checkout -- <files> / git stash drop) and record why, with the numbers |
Every outcome is logged:
python3 $PK ledger add .perf/<c> --id E<n> --hotspot … --hypothesis "… expect ~2×" --change … --compare <cmp.json> --guard "<tests + harness result>" --decision kept|reverted --quest-task <id>.
Rejected experiments are evidence, so the next person doesn't retry them blind.
If the measured gain is far below the prediction, your model of the program is wrong.
Re-profile instead of stacking guesses.
Re-profile and repeat from step 4. The bottleneck moves after every win.
Stop when any of these holds, and name which one in the report:
Confirm and report:
references/report.md): baseline, experiments kept and
rejected with numbers, remaining hotspots with ceilings, caveats.Never trade correctness or readability for an unmeasured gain. A change that makes the code harder to read needs a measured, significant gain on a hot path. Otherwise revert it, even if it might be faster.
No profile, no change. Every hypothesis cites a frame and share from a saved profile.
Never touch the measuring stick: no edits to benchmarks, workloads, fixtures, timing
harnesses, the guard, or the policy. Check git diff --stat before every claim. Fix a
broken harness as its own logged step, then re-baseline.
No gaming:
The hold-out workload exists to catch these.
One change per experiment, measured against the incumbent. Bundled changes hide regressions.
Memory and tails count. Agents almost never optimize memory, and often regress it.
Peak RSS is recorded on every A/B (--all-metrics).
tmx at R4+;.perf/<concern> and
.perf/wt-* worktrees are disposable (git worktree remove; tidy trashes .perf when
the repo lists it under [junk] patterns).Each pass works on the output of the last. When one hotspot resists, use candidate
fan-out (references/loop.md): 2–4 genuinely different approaches, each in its own
worktree or subagent, all through the same guard and one multi-arm interleaved A/B. Keep the
best that passes and log the rest. The evaluator matters more than the search, so fan out
only once steps 2–3 are solid.
references/loop.md: worktrees, function-level drivers, the ledger, stop rules, fan-out, handoff notes.references/guards.md: pinning and equivalence harnesses (Python, JS, Bash), the semantics checklist, anti-gaming checks, hold-outs.references/ladder.md: the optimization ladder per language.references/rigor.md: what R1–R5 require at each step.references/records.md: .perf/ layout and cleanup, Quest notes, the lore report, a worked example.references/report.md: lore report and PR description templates.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
Generated from the plugin's indexed repository (opum-ai/profile-skills) — no native marketplace selected
npx claudepluginhub p/opum-ai-profile-skills3 skills in this plugin
/perf-ciKeep performance from regressing as agents ship changes - adopt perf-policy.toml (benchmarks, noise-calibrated tolerances, budgets for latency, startup, memory, bundle size, query/exec counts and Core Web Vitals) on top of test-skills' R1-R5 rigor tiers, and wire a CI gate that builds base and head on the same runner, compares them interleaved and paired with a confidence-interval rule (perfkit suite + gate), reads its policy from the base branch so a PR can't loosen it, and is proven to fail on an injected regression and pass a clean change; CodSpeed, Bencher, github-action-benchmark, Lighthouse CI and size-limit where they fit. Use this skill whenever the user asks to add performance or benchmark checks to CI, catch perf regressions in PRs, set performance budgets or SLOs, track benchmarks over time, fix flaky perf tests, gate bundle size or Lighthouse scores, or add performance rules for agents to a repo. For one-off measurement use perf-measure; for optimizing use perf-optimize./perf-measureGather performance evidence without changing the code - profile to find where time or memory goes (Python, Node, Bun, browser, Bash), benchmark and compare two versions/branches/runtimes with interleaved runs and a confidence-interval verdict, verify someone's claimed speedup by independent re-measurement, or review a diff/PR for performance regressions with measured confirmation. Use this skill whenever the user asks to profile, find a bottleneck or hotspot, "why is this slow", "where is the time going", "what's using the memory", wants a flame graph, asks to benchmark or compare implementations, "is this faster", "did this regress", "is this speedup real", "will this PR be slow", "check this for perf issues", or hands you a .prof, .cpuprofile, speedscope, trace.json or benchmark JSON. To change code to make it faster use perf-optimize; to add CI gates use perf-ci.