Performance deep dive — budgets, PGO, profiling, memory
Companion to Performance. This page gives commands and numbers; that page gives the map.
Budgets with proof
Section titled “Budgets with proof”zz check --stats src/main.zz# stats: src/main.zz: 1 modules (0 cached, 1 checked), seed 878 funcs, 38.1ms# run twice: second shows cached instead of checked
zz test --slow-threshold 200zz bench --json > bench.json- Check: cold p50 ≤0.5s on 10k lines, warm ≤50ms/file.
- Test: 60s hard budget per test (
--timeout,--soft-timeoutlegacy). - Bench: serial,
warmup(default 100) untimed +iters(default 1000) timed.
PGO flows
Section titled “PGO flows”zz build -p --full main.zz -- fast representative workloadzz build --pgo main.zzzz profile main.zz -- argszz build -p --verbose main.zz # exact clang linellvm-profdata merge runs under the hood. --pgo --target <foreign> rejected
(native host only). --static rejected on macOS. Cross uses safe baseline CPU.
Profiling recipes
Section titled “Profiling recipes”# CPU on the built binaryperf record -g ./main && perf report# or Instruments (macOS), or Workers flow via workers-profiling skill
# Keep the measured code alive in AOT# test.black_box(v) — optimizer cannot see through itBench harness shares one interp/process across iterations — reset mutable state
inside the bench fn. Benches take no params, not generic, no @test mixing.
Memory: what actually allocates
Section titled “Memory: what actually allocates”| Path | Cost | Notes |
|---|---|---|
| Clone live var | O(1) refcount bump | CoW gate on write |
| Unique write | in place | no copy |
| Shared write | one copy | then in place |
bytes slice |
zero-copy share | immutable, b[i] = x errors |
str.builder / bytes.builder |
amortized push + one join | use for loops, not s = s + p |
| Spawn | ~µs + deep copy of captures | snapshot isolation |
| Channel send (uncontended) | ~25ns + mutex pair | unbounded via ring + spill |
s.f = pure, len(s.f) |
zero clones | take-restore window |
| AOT readonly param | borrowed, no retain | proven by param_escape.rs fixpoint |
| Recursive wrap build | O(n²) depth-n | prefer iteration for large inputs |
History: perf/baseline.md, perf/append-elision-report.md,
bench/, benchmarks/, performace_check/arena/bench_memory_arena.zz.
Design: design/vm-cow.md.
Checklist before claiming fast
Section titled “Checklist before claiming fast”zz benchbefore/after with--jsondiff, not wall-clock eyeballing.black_boxon inputs/outputs so AOT does not delete the bench.- Same flags both sides (
-pvs dev matters more than the code). check --statsfor checker regressions (seed size + wall time).- Commit
*.snap/bench.jsondeltas with the code, not after.