Skip to content

Performance — budgets, PGO, profiling

  • zz check cold p50 ≤0.5s on 10k lines, warm ≤50ms/file (--stats to verify).
  • zz test default 60s hard budget per test (--timeout, --soft-timeout legacy).
  • zz bench serial, warmup untimed + iters timed; never shuffle/parallelize timings.
Terminal window
zz build -p --full main.zz -- fast representative workload # LTO + training run
zz build --pgo main.zz # native host only
zz profile main.zz -- args # profile flow (llvm-profdata merge under the hood)

All builds: -O3 -flto=thin (release), -fwrapv, -fno-strict-aliasing, no -ffast-math, no -march=native. Cross uses safe baseline CPU. --verbose prints the exact clang line; manual app.c + build.sh/build.bat ship next to every binary.

Terminal window
zz bench
zz bench --engine native --json > bench.json
zz test --slow-threshold 200
  • test.black_box(v) returns its arg and blocks AOT dead-code elimination — wrap measured inputs/outputs.
  • Callgraph + DCE run before codegen; perf/ + bench/ + benchmarks/ hold history (perf/baseline.md, perf/append-elision-report.md).
  • Profile CPU with workers-profiling skill flow (deployed Workers/DOs) or local perf/ Instruments on the built binary; memory via arena benches (performace_check/arena/bench_memory_arena.zz).
  • CoW keeps clones O(1) until write; bytes slices share zero-copy.
  • take-restore windows make s.f = pure, s.f[i] = pure, len(s.f) clone-free.
  • AOT readonly-param borrows skip retains for proven read-only params.
  • Builders (str.builder/bytes.builder) turn O(n²) loops into one join.
  • fs.scan_counts fuses read+NUL-sniff+classify; str.find* are O(1) byte ops.
  • std.fs reads share one stat-validated content cache (read, read_bytes, scan_counts, is_generated, and the *_at OS provider paths). A repeated read of an unchanged regular file is one stat plus a refcount bump, and NUL/UTF-8 checks are memoized. Writes/removals through std.fs invalidate eagerly, while outside writes are caught by len/mtime (ctime/ino/dev on Unix) on every hit. Knobs: ZZ_FS_CACHE=0 disables; ZZ_FS_CACHE_MB=<n> sets the raw-buffer budget (default 96 MiB; entries up to 8 MiB; empty/non-regular files are never cached; an alternate text/bytes view adds at most one lazy copy per entry). Both the VM and the AOT C runtime implement the same policy.

History: perf/baseline.md, perf/append-elision-report.md.