Turns a suspected slow step into a patch that a script declares faster than a measured baseline, with the noise known and a negative control proving the verifier can fail. Use when one piece of code must be made faster and the speedup must be proved.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Perf Optimize?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/uniterra-solutions-perf-optimize)
---
name: perf-optimize
description: "Turns a suspected slow step into a patch that a script declares faster than a measured baseline, with the noise known and a negative control proving the verifier can fail. Use when one piece of code must be made faster and the speedup must be proved."
version: 2.0.0
author: Tsz Kin Lai (LaiTszKin), Hermes Agent
license: MIT
platforms: [linux, macos, windows]
metadata:
hermes:
tags: [software-development, performance, profiling, search, verification]
related_skills: [review, reproduce, plan]
---
# Perf Optimize — a measured bottleneck turned into a proved speedup
## Context
- **A replayable workload**: a trace or fixture that runs unattended in seconds to minutes, because a synthetic input gets fitted rather than optimised.
- **An invariant suite that can go red**, holding at least one closed-form or golden check, because a suite that only compares two implementations passes a mutation applied to shared code.
- **A mutation that breaks the suite on purpose**, with the child process inheriting the environment, because a suite that pins the mutation flag makes the control unreachable and decorative.
- **A branch the loop can wreck without consequence**, because merge is a human act and a loop that can reach the protected branch will eventually write to it.
- **A profile at the language layer and at least one layer below** — native, syscall, IO or accelerator — because a language-level profiler cannot see time spent in a native extension.
- **A record per turn, kept where a compressed context cannot lose it**: the mechanism, the measured fraction `f`, the predicted bound and the falsifier are written before the edit, and `scripts/loop.py` records and compares the numbers.
- **`references/false-wins.md`** for the failure shapes that let an unattended loop report a speedup it never measured.
## Goal
The work closes when the numbers close: an accepted patch that a script declares faster than a measured baseline, with the noise known and a negative control proving the verifier can fail.
The suspected step is a search problem rather than a single clever edit. Test structural hypotheses before touching a knob, and measure and reject two of them before a parametric search begins, because the architecture usually pins the knob. The accepted patch is the best recorded win rather than the last turn, because a worse later patch is newer and not better. The generalisable part is written back as a note or a skill edit, because a speedup that teaches nothing is one run's saving.
## Constraints
- **`gate` returns `ok:true`, `invariants_pass:true` and `negative_control_caught:true` before any edit**, because a green mutant voids every later measurement.
- **Baseline and candidate runs carry a repeated measurement with a warmup and a `cv` under the ceiling**, and the comparison decides the verdict; a run over the ceiling is `unstable` and is never rounded to a win or a no-win.
- **The accepted speedup clears 1.2x**, and between 1.2x and 1.5x the p10–p90 ranges do not overlap, because a smaller difference is inside the noise.
- **Every turn's record carries the mechanism, the measured fraction `f`, the predicted Amdahl bound `1/(1-f+f/k)` and the observation that would refute it**, written before the edit.
- **The profile runs on the current best patch**, so the next claim is anchored to the system as it now is.
- **Every record carries an objective vector** — latency, throughput, cost and one correctness scalar — and a win on one axis that regresses another is not a win without a declared weight.
- **The stop rule is stated up front** as N turns or M consecutive non-wins, and lives in a file the script reads, because an agent that forgets the budget cannot talk past it.