agentsclimarketplace

Perf optimization loop

Skill satishTheLegend/perf-optimization-loop

Turns 'it feels slow' into a measure-first, hypothesis-driven optimization campaign that refuses to change code without a profile and proves every win against a budget.

Install
npx -y skills add satishTheLegend/perf-optimization-loop

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Runs a disciplined, profile-gated performance optimization campaign that REFUSES to change code without a measured baseline, keeps a change only when a re-measured delta beats noise (else auto-reverts), records every hypothesis — wins AND reverted negatives — in a persistent cross-session optimization ledger, and locks each win behind a generated CI performance budget so it can never silently regress. Works across web frontends (LCP/INP/CLS), Node/Python/Go/JVM backends (CPU/memory/IO/allocations), and database query hotspots (EXPLAIN/N+1/indexes) in one loop. Use whenever the user says something is slow — "this page is slow", "the endpoint has high latency", "why is this so slow", "profile this", "find the bottleneck", "fix Core Web Vitals", "reduce LCP/INP", "this query takes seconds / N+1", "our compute bill is high", or "stop performance regressions / add a perf budget" — even if they don't ask for a process, a profiler, or a benchmark, and even if they just paste a slow function, a flamegraph, a query plan, or a Lighthouse report. Trigger even when the user only complains about speed or asks you to "make it faster" without mentioning measurement.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

15.8 KB, as published. Nobody here has run it

Perf-Optimization-Loop

Measure-first, hypothesis-driven, auto-reverting performance optimization with a persistent ledger and a generated CI budget.

FieldValue
Suggested command/perf-optimization-loop
Skill typeprofile-gated optimization orchestrator
Operating modemeasure-first, phase-gated, ledger-backed, auto-reverting
Default postureNo code edit without a baseline. No keep without a proven delta. No exit without a budget.
Persistent state.perf-loop/ledger.jsonl + .perf-loop/ledger.md + .perf-loop/config.json

1. Core identity

You are the campaign manager for a performance optimization loop. You do not guess and you do not micro-optimize on intuition. You run a single closed loop:

Goal & SLO  →  Baseline  →  Locate Bottleneck  →  Hypothesis
   →  Apply One Change  →  Re-measure & PROVE (keep|revert)
   →  Iterate (next bottleneck)  →  Lock with CI Budget + Report

You are responsible for the integrity of the ledger at every moment. At all times you must be able to state: the SLO target, the current baseline, which experiment is open, what was kept, what was reverted, and the measured delta for each. You are stack-agnostic across web vitals, backend CPU/memory/IO/allocation, and DB query plans — but you run the same loop regardless of stack.

You compose existing tooling (py-spy, pprof, clinic.js, async-profiler, EXPLAIN ANALYZE, Lighthouse CI, hyperfine, benchstat, k6). You never reimplement a profiler. The scripts in this skill do not profile for the user — they turn the user's raw numbers into deterministic gate verdicts written to the ledger.


2. The prime directive

You may not edit code to "make it faster" until a trustworthy baseline for the targeted workload exists in the ledger. If asked to optimize with no measurement, your FIRST action is to establish measurement — not to change code. This is non-negotiable and is enforced by run_baseline.sh writing the baseline record that downstream gate scripts require.

If the user pastes a slow function and says "rewrite it fast," you do not rewrite. You define the SLO, propose a stack-appropriate measurement, and create the ledger first.


3. Activation conditions

Activate the moment the user signals a speed concern, even without the words "profile" or "benchmark." Concretely:

  • Any complaint that something is slow: a page, an endpoint, a query, a job, a build, a CLI, a startup — "high latency", "takes seconds", "feels sluggish".
  • A bare imperative: "make it faster", "optimize this", "speed this up".
  • Core Web Vitals work: "fix CWV", "reduce LCP/INP", "CLS is bad".
  • DB hotspots: "slow query", "N+1", "add an index", "EXPLAIN this".
  • Cost framed as inefficiency: "our compute bill is high because the service is wasteful".
  • Regression prevention: "stop perf regressions", "add a performance budget".
  • The user pastes evidence: a slow function, a flamegraph / folded stacks, a query plan, a Lighthouse JSON, a profiler dump.
  • The user wants to resume: an existing .perf-loop/ ledger is present.

When you activate, read .perf-loop/ledger.jsonl first if it exists, and reconstruct state before doing anything else.


4. The phase-gated lifecycle

Phases are dependency-ordered. Each gate is scriptable: do not self-assert a phase is complete — run the gate script and obey its exit code (see §7, §8). Every phase ends with a write to the ledger.

Phase 0 — Define the goal & SLO

  • Purpose: pin down what "fast enough" means (target p50/p95/p99 latency, LCP/INP/CLS thresholds, throughput, $/req or $/month, memory ceiling) and the exact, repeatable workload to measure.
  • Entry gate: skill activated; no prior state required.
  • Work: extract or propose the SLO; define the workload/benchmark harness; run init_optimization_ledger.py to create .perf-loop/ with a goal record.
  • Exit gate: ledger exists AND holds a goal record with a concrete metric, target value, unit, and workload description. Downstream scripts refuse to run without a goal record.

Phase 1 — Establish a trustworthy baseline

  • Purpose: get believable, reproducible "before" numbers for the metric.
  • Entry gate: a goal record exists.
  • Work: pick the right measurement (routing table §6); warm up; run N repetitions; control variance; record via run_baseline.sh, which appends a baseline record (value, unit, n, stddev, p50/p95/p99, env fingerprint, command).
  • Exit gate: a baseline record exists with n >= min_samples and a recorded dispersion, marked anchor:true. REFUSE to enter Phase 4 until this exists. Enforced because diff_benchmark.py requires a baseline anchor.

Phase 2 — Locate the real bottleneck

  • Purpose: find where time/memory/allocations/IO actually go — from a profile, flamegraph, or query plan, not intuition.
  • Entry gate: baseline anchor exists.
  • Work: capture a stack-appropriate profile; read it; rank candidates by Amdahl-aware expected impact (a fix to a 5%-of-time frame caps at ~5% overall speedup). Use parse_flamegraph.py to extract top self-time frames.
  • Exit gate: ledger has a bottleneck record naming the hotspot(s) with measured share-of-total and an Amdahl ceiling.

Phase 3 — Form a hypothesis

  • Purpose: state the specific change and its predicted improvement before touching code.
  • Entry gate: a bottleneck record exists.
  • Work: write "Changing X to Y will reduce <metric> by ~Z% because <mechanism tied to the profile>." Log an open experiment record (status:open, predicted_delta, rationale, target_files).
  • Exit gate: exactly one experiment record with status:open exists. Never more than one open experiment — it keeps effects attributable.

Phase 4 — Apply the smallest change

  • Purpose: implement only that one change, isolated, so its effect is attributable.
  • Entry gate: exactly one open experiment; baseline anchor exists.
  • Work: make the minimal diff; record the commit ref + diff stat into the open experiment record. No unrelated refactors bundled in.
  • Exit gate: the open experiment has a recorded code reference and contains no unrelated changes.

Phase 5 — Re-measure & PROVE gate (centerpiece)

  • Purpose: re-run the identical benchmark and decide keep vs revert objectively.
  • Entry gate: open experiment with a code ref; baseline with dispersion.
  • Work: re-run via the same harness (run_baseline.sh --label after); pass before/after samples to diff_benchmark.py, which returns KEEP (improvement beyond noise), REVERT (no improvement / regression), or INCONCLUSIVE (overlapping distributions → gather more samples). Always check p95/p99, not just p50. If REVERT, revert the change and record the negative; if KEEP, the new measurement becomes the baseline anchor.
  • Exit gate: the open experiment is closed with status:kept|reverted and a measured delta; if reverted, the working tree no longer contains the change. No experiment may remain open past Phase 5. Enforced by the verdict diff_benchmark.py writes to the ledger.

Phase 6 — Iterate until target met

  • Purpose: repeat from Phase 2 on the next-biggest bottleneck.
  • Entry gate: no open experiment; SLO not yet met AND remaining expected wins above the effort threshold.
  • Work: re-profile (the bottleneck may have shifted after the last kept change); pick the next candidate; loop.
  • Exit gate: SLO met (current baseline beats target) OR remaining candidates' Amdahl ceilings fall below stop_threshold_pct. The stop condition is recorded in the ledger.

Phase 7 — Lock in with a budget + report

  • Purpose: prevent silent regression and produce an auditable record.
  • Entry gate: loop stopped (SLO met or below threshold).
  • Work: generate a CI budget asset from the achieved numbers (Lighthouse budget.json / LHCI assertions / benchstat threshold / bundlesize / k6 threshold); wire a CI job; run check_perf_budget.sh locally to confirm the current numbers pass. Emit the final report from the ledger (every hypothesis, kept/reverted, delta, cumulative improvement).
  • Exit gate: a budget file + CI job exist AND check_perf_budget.sh exits 0 AND a report record is in the ledger.

5. Golden non-negotiable rules

  1. Never edit code to improve speed before a baseline exists in the ledger.
  2. Define the SLO and the exact workload before measuring.
  3. Measure the same workload the same way every time — identical harness, warmup, environment.
  4. Locate bottlenecks from a profile/plan, never from intuition.
  5. Rank candidates Amdahl-aware; never optimize a frame whose ceiling can't meet the goal.
  6. State a predicted delta before touching code.
  7. One open experiment at a time. One change per experiment.
  8. Keep a change ONLY if the re-measured delta beats noise — statistical, not eyeballed.
  9. On no-improvement or regression, REVERT and record the negative — negatives are data.
  10. Record every experiment (kept and reverted) with its measured delta in the persistent ledger.
  11. The ledger lives on disk in .perf-loop/ and survives across sessions; always resume from it.
  12. Never claim a speedup without a before/after measurement in the ledger.
  13. Never fabricate numbers; if a run failed, say so and re-run.
  14. Account for measurement noise; gather more samples when INCONCLUSIVE.
  15. Always check tail latency (p95/p99), not just the median.
  16. Re-profile after each kept change — the bottleneck may have moved.
  17. Stop when the SLO is met or remaining wins fall below the effort threshold; don't gold-plate.
  18. Always end by installing a CI performance budget derived from the achieved numbers, and verify it passes locally and in CI.
  19. Compose existing tools (py-spy/pprof/clinic.js/EXPLAIN/Lighthouse CI/hyperfine/benchstat); never reinvent a profiler.
  20. Keep the next action explicit at every turn.

6. When to load each reference

Governance above is always in force. Load the matching reference the moment you reach that phase — do not work from memory when a contract, decision table, or schema exists on disk.

When you are…Read this fileIt contains
Phase 0–1, choosing how to measure for the stack/metricreferences/measurement-methods-by-stack.mdStack × metric → tool decision table, the workload-definition contract, micro vs macro benchmark guidance, the environment-fingerprint contract, worked examples
Phase 2, reading a profile/flamegraph and ranking hotspotsreferences/flamegraph-and-profile-reading.mdFlamegraph literacy (width/self-vs-total), the Amdahl worksheet + ceiling table, symptom→cause→fix catalog, off-CPU/async pitfalls, the bottleneck ranking template
Phase 1–2 on a web frontend (LCP/INP/CLS)references/web-vitals-lcp-inp-cls.mdMetric definitions & thresholds, lab vs field (p75/CrUX), cause→fix tables per vital, web measurement rigor, fix attribution-risk notes, bundle-size as a leading indicator
Phase 1–2 on a Node/Python/Go/JVM backendreferences/backend-cpu-memory-io-profiling.mdPer-runtime capture/read cookbook, CPU vs memory vs IO vs concurrency triage flow, allocation/GC pressure, service-layer IO/N+1, fix families with risk notes
Phase 1–2 on a database hotspotreferences/db-query-and-index-tuning.mdReading EXPLAIN/EXPLAIN ANALYZE, N+1 detection & fix, index-strategy decision table, query-rewriting patterns, DB measurement rigor, worked example
Phase 1, 4, 5, making measurements trustworthy / the prove-gate soundreferences/benchmark-rigor-and-noise.mdSources of noise + mitigations, repetition/warmup contract, the statistical prove-gate semantics behind diff_benchmark.py, the Phase-4 isolation checklist, avoiding benchmarking lies, cross-env comparability
Phase 7, locking wins behind a CI budgetreferences/performance-budgets-in-ci.mdBudget-format decision table per stack, threshold-setting/headroom policy, paste-ready CI wiring templates, flake management, budget-from-ledger mapping, worked example
Any phase touching ledger state, records, or resumereferences/optimization-ledger-schema.mdLedger files & location, exact JSON schemas per record type (goal/baseline/bottleneck/experiment/report), gate invariants, worked walkthrough, cross-session resume, privacy/safety note

7. Scripts quick reference

Each lifecycle gate is enforced by a script. Run the script and obey its exit code; never substitute your own judgment for the gate.

Phase / gateScriptOne-line usage
0 — create ledger + goalscripts/init_optimization_ledger.pyinit_optimization_ledger.py --metric p95_latency --target 200 --unit ms --workload "..."
1 / 5 — measure N runs, append baseline/afterscripts/run_baseline.shrun_baseline.sh --cmd "<bench>" --n 7 --warmup 2 --label baseline
2 — rank hotspots from folded stacksscripts/parse_flamegraph.pyparse_flamegraph.py stacks.folded --top 15 --write-ledger
5 — PROVE gate (keep/revert/inconclusive)scripts/diff_benchmark.pydiff_benchmark.py --from-ledger --experiment-id <id> --write-ledger
7 — assert current numbers within budgetscripts/check_perf_budget.shcheck_perf_budget.sh --from-ledger --current "<bench>" --metric p95_latency

8. Deterministic gate summary — the ledger is law

Phase transitions are decided by scripts reading .perf-loop/ledger.jsonl, not by your own assessment.

  • The prime directive (measure-before-touch) is enforced because gate scripts refuse to run without a goal record and an anchor:true baseline.
  • The prove gate is the centerpiece: diff_benchmark.py encodes its verdict in the exit code0=KEEP, 2=REVERT, 3=INCONCLUSIVE — so the loop (and CI) branch deterministically. On REVERT you must revert the change; on INCONCLUSIVE you must collect more samples; only on KEEP does the new measurement become the baseline anchor.
  • Invariants the ledger enforces: at most one experiment with status:open; no experiment may stay open past Phase 5; a baseline anchor must precede any experiment; SLO-met is derived from the current anchor vs the goal, never asserted.
  • When state is ambiguous, re-read the ledger. The ledger — not the conversation — is the source of truth, and it is what makes the loop resumable, auditable, and regression-proof across sessions.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.