3 +description: "Benchmark and optimize code across performance, memory, startup, I/O, network, concurrency, algorithmic, caching, config categories, plus meta-level: doing less, mechanical sympathy, architecture fixes."
4 +disable-model-invocation: true
9 +**Target**: $ARGUMENTS
13 +1. **Profile** → find hotspots with canonical profiler for runtime+OS. tracing/wall-time fallback OK.
14 +2. **Choose measurement** → match tool to scope:
15 + - in-process → microbenchmark
16 + - CLI/process → end-to-end timing
17 + - CPU → CPU profiler
18 + - memory/alloc → heap profiler
19 + - I/O/network → tracing
20 +3. **Baseline** → repeatable benchmark before changes.
21 +4. **Analyze** → connect measurements to code. explain bottleneck.
22 +5. **Optimize** → change only measured bottlenecks.
23 +6. **Verify** → re-run baseline/candidate. statistical comparison. report variance, significance, regressions.
24 +7. **Document** → record methodology + rationale for non-obvious optimizations.
26 +##
Benchmarking Rigor 28 +- **warmup** → run before measurement; discard. stabilizes JIT, caches, branch predictors.
29 +- **outliers** → detect and remove. use IQR or MAD; report removed count.
30 +- **effect size + confidence intervals** → report magnitude and interval, not just p-values. statistical significance ≠ practical significance.
31 +- **repetition** → count based on variance source: between-build > between-execution > between-iteration. more reps for noisier sources.
32 +- **isolation** → control environment: disable auto-updates, pin CPU frequency, avoid concurrent load.
36 +- performance / hot paths
37 +- memory / allocations / reclamation
38 +- startup / cold-start / init cost
39 +- I/O / disk / syscalls / buffering
40 +- network / requests / caching / retries
41 +- concurrency / locks / worker pools
42 +- algorithmic / complexity / data structures
43 +- caching / memoization / invalidation
44 +- config / build / deps / compiler flags
46 +multiple categories? prioritize by impact + measurability.
50 +- **doing less** → same goal, fewer instructions. [ref](references/doing-less.md)
51 +- **mechanical sympathy** → substrate awareness (runtime, VM, CPU, network, API). structure data + instructions efficiently. includes data-oriented design. [ref](references/mechanical-sympathy.md)
52 +- **architecture** → system-level design wrong? serial vs batched, coupling, sync vs async. [ref](references/architecture.md)
56 +common mistakes spanning all categories. review before profiling. [ref](references/anti-patterns.md)
60 +- [anti-patterns](references/anti-patterns.md)
61 +- [memory](references/memory.md)
62 +- [startup](references/startup.md)
63 +- [io](references/io.md)
64 +- [network](references/network.md)
65 +- [concurrency](references/concurrency.md)
66 +- [algorithmic](references/algorithmic.md)
67 +- [caching](references/caching.md)
68 +- [config-build](references/config-build.md)
69 +- [doing-less](references/doing-less.md)
70 +- [mechanical-sympathy](references/mechanical-sympathy.md)
71 +- [architecture](references/architecture.md)
75 +tool choice = part of the work. no hardcoded profiler/benchmark/comparison tool.
76 +prefer canonical tools available for runtime+OS+repo. prefer existing repo automation.
78 +missing tooling? stop. say exactly which tool + why. ask to install/enable. no silent substitution. no dep/system/build changes without approval.
82 +run tests. untested code → write tests first. system/dep/build changes → report.