perf-optimization
Skill308 starsChanged 37 days agoApache-2.0View on GitHub
Profile-driven performance optimization of mecatl using the offline benchmark + scenario harness. Use when optimizing allocations or latency, reducing allocs/op or memory, profiling a Go benchmark, pinpointing a hotspot with pprof, proving a win with benchstat, adding a regression benchmark, wiring profile-guided optimization (PGO), or investigating "why is this slow / allocating" or a suspected perf regression. Covers task bench, task perf:scenarios, memprofile -> pprof, benchstat A/B, allocs-first gating, PGO setup, and the discipline (follow the profile not the hypothesis; keep pure-perf changes byte-identical; mutation-test cache guards; skip the wrong abstraction). NOT for the live perf MCP server (use perf-mcp-interpretation) or non-mecatl Go profiling.
- Installs packages
5 other projects use a version of this.
Adopted by
Most recently taken up by
- matthewmturner/skillstheir own version, first seen Nov 8, 2026
- irahardianto/awesome-agvtheir own version, first seen Oct 14, 2026
- Saddss/cursor-skillstheir own version, first seen Aug 29, 2026
- NVIDIA/TensorRT-LLMtheir own version, first seen Aug 17, 2026
- microsoft/code-optimizations-skillstheir own version, first seen Jun 8, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- NVIDIA/TensorRT-LLM★ 15ksame name
- irahardianto/awesome-agv★ 157same name
- microsoft/code-optimizations-skills★ 5same name
- Saddss/cursor-skills★ 2same name
- matthewmturner/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- engine/AGENTS.mdAGENTS.md
- internal/AGENTS.mdAGENTS.md
- user-docs/AGENTS.mdAGENTS.md
- website/AGENTS.mdAGENTS.md
- cut-releaseSkill
- mecak8s-kind-manual-verifySkill
- mecatl-learning-configSkill
- mecatl-model-router-configSkill
- panel-reviewSkill
- perf-mcp-interpretationSkill
- tech-writerSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 58
Run the relevant benchmark and confirm it reflects the workload you care about.
- Very specific: line 98
Update the baseline snapshot in docs/perf-tracking.md.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Perf optimization (mecatl offline harness)
The companion to the regression-tracking design in
docs/perf-tracking.md. This skill
is the offline benchmark/scenario workflow: measure → profile → optimize →
prove → guard. For diagnosing a running harness via the perf MCP server, use
the perf-mcp-interpretation skill instead — different tool, different signals.
The harness (where the numbers come from)
task bench— hot-path microbenchmarks (engine/prompt,engine/governance,engine/agent).BENCHCOUNTdefault 10. Offline (mockllm + memfs). Not part oftask test. The engine is its own Go module, sotask bench/task fuzzrun these ascd engine && go test … ./prompt/ ./governance/ ./agent/. An ad-hoc re-run on an engine package must do the same:cd engine && go test -bench=… ./agent/(an explicit./engine/agent/path also resolves via the committedgo.work, but the./...wildcard does not cross the module boundary).task perf:scenarios— five whole-loop scenarios. Four live inperf/scenarios/(single-session-long, team-fanout, background-subagents, compaction-cycle); the fifth (tui-scrollback) lives incmd/mecatui/ui/, and the task runs both packages — sogo test ./perf/scenarios/alone gives only four.BENCHCOUNTdefault 6.MECATL_PERF_JSON=.scratch/x.jsonwrites the KPI JSON.- Both are deterministic and offline — never reach for a live model/network.
- PGO/bench captures over
engine/packages depend on the activego.work(the committed workspace wires./enginein alongside the root) — aGOWORK=offinvocation resolves the engine module standalone and won't see the host repo.
What to gate on (allocs-first)
allocs/op, bytes/op, goroutine-delta, and cache-hit-rate are deterministic and
portable — these are the real signal. ns/op and rss_* are machine-specific —
treat as advisory shape, never the headline. A perf change is done only when
allocs/op moves in benchstat; a wall-clock-only "win" on a shared machine is noise.
Workflow
1. Measure — pick the benchmark that actually exercises the path
Run the relevant benchmark and confirm it reflects the workload you care about. A
benchmark whose per-iteration setup dwarfs the code under test, or that is
all-miss by construction, will hide a real win. If no benchmark covers the path,
add one first (match the existing bench_test.go style: for b.Loop(), results to a
package-level sink, offline).
2. Profile — pinpoint the site, do NOT guess
Capture an allocation profile on the benchmark and follow it to a file:line:
go test -run='^$' -bench=BenchmarkX -benchmem -memprofile=.scratch/x.mprof -count=3 ./pkg/
go tool pprof -alloc_space -top -nodecount=25 .scratch/x.mprof # bytes
go tool pprof -alloc_objects -top -nodecount=25 .scratch/x.mprof # object count
go tool pprof -list=FuncName .scratch/x.mprof # line-levelSave profiles under .scratch/ (repo rule — never /tmp). Follow the profile to
the real site. The hypothesis is often wrong (see the playbook: the TUI hotspot was
the string join, not SetContent as assumed). Let -list show you the exact lines.
3. Design — the smallest change at the proven hotspot
Optimize only what the profile proves is hot. Weigh the win against the real cost: a microsecond saved once per turn is invisible next to an LLM round-trip. The wrong abstraction is worse than the allocation — if the clean seam doesn't exist or the fix adds stateful invalidation surface for a marginal gain, it is a legitimate NO-GO. Say so and skip it rather than forcing it.
4. Prove — benchstat before/after, count >= 10
go test -run='^$' -bench=BenchmarkX -benchmem -count=10 ./pkg/ > .scratch/before.txt
# ... apply the change ...
go test -run='^$' -bench=BenchmarkX -benchmem -count=10 ./pkg/ > .scratch/after.txt
benchstat .scratch/before.txt .scratch/after.txt # go install golang.org/x/perf/cmd/benchstat@latestallocs/op / B/op must drop with a statistically significant delta. Re-run
task perf:scenarios and confirm the scenario KPI moved in the expected direction.
Update the baseline snapshot in docs/perf-tracking.md.
5. Guard — keep behaviour identical, prove the guard isn't vacuous
- Pure-perf changes must be byte-identical. For the TUI,
task test:goldenmust stay green with zero golden diffs — you change HOW, never WHAT. Caveat: golden refresh runs-updatefirst, so a plaingo test ./...(no-update) against the committed goldens is what actually catches a regression; don't rely on the refresh step to catch a stale serve. - Any cache/oracle you add must be mutation-tested. Temporarily break it (force
the stale/wrong path), confirm a test goes red, then restore (back up with
cp, restore withcp— nevergit checkout, it wipes uncommitted work). A guard that stays green when the behaviour is broken is worse than none. - A perf change touching an EXPORTED
engine/symbol trips theapi-compatCI gate (task api:check) — a failure mode a perf optimizer wouldn't expect. Keep pure-perf changes byte-identical to the engine's public surface and it never fires; if the surface legitimately changed, runtask api:updateand add anengine/CHANGELOG.mdentry classified perengine/COMPATIBILITY.md.
Common pitfalls
- All-miss benchmark hides the win. A streaming bench that mutates state every iteration never hits the cache you added — it's the worst-case floor, flat by design. Add a steady-state bench for the cache-hit path to show the real win.
- Setup swamps the signal. Build fixtures outside
b.Loop(); confirm with a quick profile that setup isn't the dominant allocator. - Chasing
ns/opon a shared machine. Gate on allocs; ns is advisory. - Memoizing across the byte-stable prompt prefix. Any prompt-inventory cache must produce byte-identical output or it tanks the provider cache-hit rate — the exact thing perf-tracking exists to protect. Usually not worth it (see playbook).
Complementary: PGO (free compiler-level wins)
Beyond hand-optimizing a hot path, Profile-Guided Optimization lets the compiler optimize from a CPU profile (typically 2–14% CPU — but here sub-1% of wall-clock, since cost is network-dominated: a free set-and-forget win, not a latency feature). The mechanism is already wired:
task pgo:collectbuilds a PROVISIONAL offline profile under.scratch/pgo/.cmd/mecated/default.pgois the reserved slot —go build's-pgo=autoapplies it automatically the moment a profile is dropped there (nothing in the build chain passes-pgo=off).- Do NOT commit an offline-collected profile — it trains the compiler on the
mockllm path that ships in no production binary (it can't pessimize, but it wastes
the one slot). Commit only a real
/debug/pprof/profilecapture from a runningmecatedunder load.
Full rationale, the per-binary decision, and the production refresh + staleness
process live in perf-tracking.md "Profile-guided optimization" —
read it before touching PGO.
See Also
references/playbook.md— pprof flag cookbook + two worked examples (a real win and a real NO-GO) showing the discipline end to end.docs/perf-tracking.md— the KPI design, gating posture, and baselines.perf-mcp-interpretationskill — the live counterpart (running-harness diagnosis via the perf MCP server).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

