cleanup
無料Cleanup code, optimize, refactor, delete the 80% to keep the 20%
日本語の概要は準備中です。原文の説明を表示しています。
Micro-benchmark and iteratively improve hot paths in any codebase — baseline first, mandatory improvement suggestions (bottleneck + 3 creative ideas + recommended next step), bounded attempts, user lock-in checkpoints, then human WHY comments after lock-in. Use when the user asks to benchmark, profile, optimize performance, compare implementations, or measure µs/op before shipping perf changes. Applies to Bun/Node, React, Next.js, browser code, and extensions.
日本語の概要は準備中です。原文の説明を表示しています。
実行スコア 未検証
インストール方法を見るインストールする前に、エージェントに与えられる指示の中身を確認できます。
Encode process, not target numbers. Numbers change; the workflow stays fixed.
Measuring a live page / tab / paint (DOM, RSC, navigation)?
├── Yes → Available browser tools + CDP is enough. Do not copy a µs harness.
│ Round 0 = nodes, images, TTFB, nav ms, heap. Report ms, not µs/op.
└── No (pure function / mapper / transform)
├── Harness exists in repo? → use tools/benchmark-*.mjs or scripts/bench/*
└── No → copy from this skill's `scripts/` folder
benchmark-harness.mjs + benchmark-run-all.mjs
add package.json script: "benchmark": "bun tools/benchmark-run-all.mjs"
| Artifact | Typical location |
|---|---|
| Benchmark suites | tools/benchmark-<domain>.mjs or scripts/bench/<domain>.mjs |
| Shared harness | benchmark-harness.mjs (same dir as suites) |
| Domain catalog | tools/benchmark-domains.md (optional; use domains-template.md) |
| Stack notes | stacks.md — React, Next.js, Node, DOM, IDB |
Benchmarks are not in CI. They are local decision tools before merging perf work.
Is this a perf investigation or a perf change?
├── Investigation only → run suites → Round 0 table → Suggest block → stop (unless user picks a suggestion)
└── Perf change → Improvement loop + Steps 1–6
No benchmark suite exists for this domain yet?
├── Yes → read hot path in src/ → propose suite outline in Suggest block → ask user before scaffolding
└── No → run existing suite
What surface are you measuring?
├── Pure function (no DOM, no I/O)
│ └── Import from src/ directly; use bench / benchSamples
├── React / Next client component
│ └── happy-dom or jsdom; see stacks.md
├── Server handler / RSC data path
│ └── Mock Request; bench transform only — see stacks.md
├── DOM pipeline (offline / unit)
│ └── happy-dom + HTML fixtures
├── Storage (IDB, SQLite)
│ └── polyfill in test runtime OR manual trace — never fake
└── Full page / tab / cold start / “which view is heavy?”
└── Live browser + CDP. Valid Round 0. No harness, no Lighthouse required.
Live DOM / CDP is first-class, not a fallback. Open the real page, lock the tab, Runtime.evaluate + Performance.getMetrics. A table of nodes / images / TTFB / heap is the baseline. Skip copying benchmark-harness.mjs unless you are timing a pure function. Use the web-perf skill only when you need CWV / Lighthouse — not for “how fat is this tab?”
Stack-specific setup: stacks.md.
Always output this after Round 0 — investigation-only and improvement loop. Do not stop at a table alone. Do not jump straight to coding without surfacing suggestions unless the user already said "implement #1".
After benchmark numbers are in chat
├── Write Suggest block (template below)
├── State one Recommended next step (single sentence, bold the verb)
└── Then:
├── Investigation only → wait for user pick
└── Improvement loop → Phase B uses the same 3 ideas; ask before Attempt 1 unless user said "try #1" / "proceed"
### Bottleneck
<1–2 sentences: what dominates µs/op from numbers + a quick read of the hot path>
### Worth optimizing?
<Yes | Probably not | Need more data> — <one line tied to ship gate: ≥1.15× or ≥100µs user-visible>
### Ideas
1. **<Structural>** — <what> · <why from bottleneck> · risk: low|med|high
2. **<Cache / amortize>** — …
3. **<Less work>** — …
**Recommended next step:** <Try idea #N | Add benchmark for `<fn>` first | Lock in — already within noise | Stop — cost > payoff>
| Rule | Why |
|---|---|
| Exactly 3 ideas, one per kind (structural / cache / less work) | Same breadth as Phase B |
| Recommend one next step — never leave a flat list | Agent proposes, not only measures |
| Tie every idea to Round 0 numbers or code path | Untethered ideas read generic |
| If cold path is ≥3× slower than warm, one idea must address cold | Warm-only wins often lie |
| If no suite exists and the surface is a pure function, recommend scaffold benchmark first | Can't optimize what you can't measure. Live page/tab → CDP table is enough; do not scaffold a harness. |
At user checkpoint, repeat a one-line Suggestion: (I'd lock in #2 because…) | Informed nudge |
Investigation-only still suggests. Reporting numbers without ideas forces the user to invent the strategy.
Walk this tree every optimization session. Never skip Phase A. Never implement before Phase B. Never run attempt 4+ without a user checkpoint.
Enter improvement loop
├── Phase A — Freeze baseline (Round 0)
├── Phase B — Three creative hypotheses
├── Phase C — Attempt rounds (max 3 before checkpoint)
│ └── After each attempt → user checkpoint
└── Phase D — Lock in (user chose "Lock in")
└── Document WHY in src/ (final step — always)
Do this before editing production code or adding experiment branches.
npm run benchmark / bun run benchmark).Round 0 — baseline (production)
<domain> · fixture/payload · <runtime> <version>
<label> XX.XX µs/op (reference)
[cold row if caching exists]
User-visible action: <search | render | save | API call | …>
Why: Every later attempt compares to Round 0. Comparing attempt 2 only to attempt 1 hides regressions vs shipped code.
Immediately after Round 0, output the Suggest block. Phase B reuses those 3 ideas (refine if code read changed your mind — say what changed).
Same content as Suggest block → Ideas, ranked by ROI. If you already posted Suggest block in Phase A, write:
Phase B: attempting ranked idea #<N> — <title> (user confirmed | user said proceed | default #1 after suggest)
Output the ranked list only when Suggest block was skipped (user jumped straight to "optimize X").
For each idea when listing fresh:
src/ or benchmark variant namelow | med | high| Slot | Kind | Example angles |
|---|---|---|
| 1 — Structural | Algorithm, data layout, precompute, typed arrays | Precompute lookup table; flatten nested loop |
| 2 — Cache / amortize | Memo, batching, reuse, warm vs cold | Normalized cache keys; shared Map vs per-call |
| 3 — Less work | Early exit, skip work, smaller scan, defer | Reject cheap before expensive; cap walk depth |
Rank 1 → 3 by expected ROI. Attempt order follows that rank.
Hard limit: at most 3 implementation attempts per checkpoint cycle.
For each attempt:
Attempt N (<idea title>)
- [ ] assertSameResults (Step 1) — fail → fix or abandon, do not bench
- [ ] Warm bench vs Round 0 baseline
- [ ] Cold bench vs Round 0 (if caching exists)
- [ ] Ship gate (Step 3) — pass/fail with numbers
- [ ] User checkpoint (below) — mandatory before next attempt
Report format:
Round 0 — baseline XX.XX µs/op
Attempt N — <label> YY.YY µs/op Z.ZZ× vs Round 0
Ship gate: pass | fail (<which criterion>)
Keep experiment variants in the same benchmark file until lock-in. Label rows clearly (E1:, E2:).
Stop coding. Ask the user to choose one:
| Option | Agent does next |
|---|---|
| Lock in | Phase D — ship winning attempt, delete losers |
| Try next idea | Next ranked hypothesis from Phase B |
| More ideas | New Phase B (3 fresh hypotheses); resets attempt counter |
| Stop | Revert uncommitted experiments; leave production unchanged |
End with: **Suggestion:** <I'd Lock in | Try #N | More ideas | Stop> — <one sentence why>
If 3 attempts are used without Lock in or More ideas, must checkpoint — no silent 4th attempt.
Only after user chooses Lock in.
src/.Locked in: <one-line what changed>
Round 0 → shipped: XX.XX → YY.YY µs/op (Z.ZZ×)
User-visible: <action improved>
Cold path: unchanged | ±N% (note if tradeoff accepted)
src/ — see Step 7. Perf work is not done until a future reader knows why the odd-looking code exists.Never lock in an attempt that failed assertSameResults or ship gate without explicit user override.
Add comments only after lock-in — not during experiments.
Did the lock-in change behavior a reader wouldn't guess?
├── No (rename, move, obvious one-liner) → no comment
└── Yes
├── Memo / cache / fast path / different algorithm?
│ └── Comment WHY — user scenario + repeated work avoided
├── Accepted tradeoff (warm vs cold, memory for speed)?
│ └── Comment the tradeoff in plain language
└── Skipped work (early exit, smaller scan)?
└── Comment what we stopped doing and when it applies
| Rule | Why |
|---|---|
| WHY only — never narrate what the next line does | Obvious code needs no comment |
| User-visible scenario — page load, search keystroke, render | Ties optimization to product context |
Never paste µs/op, speedup multiples, or Big-O into src/ | Numbers rot |
| 1–2 lines max per optimization site | Long essays dilute signal |
| Human tone — write for the next maintainer | Plain language beats jargon |
// Good — WHY in human terms
// Same rgb string appears on dozens of nodes in one render — remember the parse.
const resolveRgbCached = memoizeString(resolveRgbRaw);
inputs covering edge cases.assertSameResults(label, candidate, reference, inputs) from harness.| Rule | Value | Why |
|---|---|---|
| Always warmup | ≥ 20 iterations, or 10% of timed iterations | JIT skew |
| Default timed iterations | 400 cheap; 40–100 expensive (DOM, zip) | Volume vs stability |
| Report metric | µs/op = (elapsed_ms / total_ops) × 1000 | Comparable |
| Compare speedup | vs explicit reference row | No cherry-picking |
| Cold vs warm | Run both when caching exists | Users hit cold on first use |
| Environment note | Record runtime version in chat/PR | Absolute µs/op is machine-specific |
Does the code memoize?
├── Yes → cold = fresh cache per op OR bypass path
└── No → cold = warm only (label it)
Per attempt:
- [ ] Reference = Round 0 production
- [ ] assertSameResults passes
- [ ] Warm benchmark vs Round 0
- [ ] Cold benchmark vs Round 0 (if caching)
- [ ] Realistic payload documented
- [ ] Ship gate evaluated
- [ ] User checkpoint answered
Why 1.15×: Below that, noise and maintenance dominate.
tools/benchmark-<domain>.mjs#!/usr/bin/env bun
/**
* Benchmark <domain> — <one line>.
* Run: bun tools/benchmark-<domain>.mjs
*/
import { bench, benchSamples, printSection, assertSameResults } from "./benchmark-harness.mjs";
import { productionFn } from "../src/<module>.ts";
// 1. inputs + assertSameResults
// 2. const reference = benchSamples(...)
// 3. const candidate = benchSamples(...)
// 4. printSection("Title", [reference, candidate], reference);
Rules:
src/ — never fork logic unless comparing abandoned baseline (label clearly).tests/ — tests assert correctness; benchmarks measure time.<Domain>
────────────────────────────────────────────────────────────────────────
<label> XX.XX µs/op X.XX× vs ref
See stacks.md for React, Next.js, Node/Bun, DOM, IDB, extensions.
Project-specific hot paths: maintain tools/benchmark-domains.md from domains-template.md.
benchmark-domains.md if a new hot path exists.src/.Treat perf-rules.md like eslint policy for hot paths: short, actionable, no golden numbers in repo code.
console.time alone — use harness µs/op.src/ comments.まだレビューはありません。使ってみた感想をお寄せください。
ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。
まだコメントはありません。最初のコメントを書いてみませんか。
Cleanup code, optimize, refactor, delete the 80% to keep the 20%
日本語の概要は準備中です。原文の説明を表示しています。
Applies the Elon Musk Algorithm to coding, product, SaaS, design, and current issues. Use when the user invokes /elon or requests Elon Musk-style first-principles analysis.
日本語の概要は準備中です。原文の説明を表示しています。
Build, run, or update minimal evaluation benchmarks for AI prompts, LLM calls, multi-model comparisons, and core functions. Use when creating new eval scripts, comparing models side-by-side, filtering specific candidate models, running benchmarks, or inspecting eval.md output artifacts.
日本語の概要は準備中です。原文の説明を表示しています。
Generates browser extension brand icons, Chrome Web Store promo tiles, promotional screenshots, brand guides, and listing copy. Uses OpenRouter gpt-image-2 via lib/blog-image-generator. Use when creating extension branding, Chrome Web Store assets, app icon concepts, store descriptions, or /extension-store-assets workflows.
日本語の概要は準備中です。原文の説明を表示しています。
Optimizes code, queries, and features based on actual usage by removing unused fields, aggregations, JOINs, and unused complexity. Use when the user invokes /optimize or asks to slim queries to what the UI actually uses.
日本語の概要は準備中です。原文の説明を表示しています。