Performance — budgets, PGO, profiling
Budgets
Section titled “Budgets”zz checkcold p50 ≤0.5s on 10k lines, warm ≤50ms/file (--statsto verify).zz testdefault 60s hard budget per test (--timeout,--soft-timeoutlegacy).zz benchserial,warmupuntimed +iterstimed; never shuffle/parallelize timings.
PGO and optimization
Section titled “PGO and optimization”zz build -p --full main.zz -- fast representative workload # LTO + training runzz build --pgo main.zz # native host onlyzz 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.
Measuring
Section titled “Measuring”zz benchzz bench --engine native --json > bench.jsonzz test --slow-threshold 200test.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-profilingskill flow (deployed Workers/DOs) or localperf/Instrumentson the built binary; memory via arena benches (performace_check/arena/bench_memory_arena.zz).
Fast paths to know
Section titled “Fast paths to know”- CoW keeps clones O(1) until write;
bytesslices share zero-copy. take-restorewindows makes.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_countsfuses read+NUL-sniff+classify;str.find*are O(1) byte ops.std.fsreads share one stat-validated content cache (read,read_bytes,scan_counts,is_generated, and the*_atOS provider paths). A repeated read of an unchanged regular file is onestatplus a refcount bump, and NUL/UTF-8 checks are memoized. Writes/removals throughstd.fsinvalidate eagerly, while outside writes are caught bylen/mtime(ctime/ino/devon Unix) on every hit. Knobs:ZZ_FS_CACHE=0disables;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.