diff options
| -rw-r--r-- | build.zig | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -128,8 +128,23 @@ pub fn build(b: *std.Build) void { const enable_jpx = b.option(bool, "jpx", "JPEG 2000 in PDFs, for scanned documents (default on; -Djpx=false drops openjpeg)") orelse true; const is_web_target = target.result.cpu.arch == .wasm32 and target.result.os.tag == .freestanding; const is_p4_target = target.result.cpu.arch == .riscv32 and target.result.os.tag == .freestanding; - // wasm: size is the budget - const optimize = if (is_web) .ReleaseSmall else requested_optimize; + // wasm: size is the budget. + // + // p4: Debug is not a supported mode, and `-Doptimize` defaulting to it made the naive + // `zig build -Dplatform=p4` produce an object that cannot run. Debug wraps every tier in + // `allocators.zig` in a `DebugAllocator`, whose metadata is page-granular; the board hands the + // editor a 384 KiB heap and one 4 KiB page per size class does not fit in it, so the image + // links and then dies in `Pardes.init`. ReleaseFast rather than ReleaseSmall because it was + // measured on the die and not chosen: against ReleaseSmall it is 13% off the fixed + // per-keystroke cost and 36% off the per-character cost, for 35% more flash on a partition + // that is 39% used. See experiments/report.typ. An explicit `-Doptimize=` still wins, so + // ReleaseSmall remains one flag away when flash matters more than latency. + const optimize = if (is_web) + .ReleaseSmall + else if (is_p4_target and requested_optimize == .Debug) + .ReleaseFast + else + requested_optimize; // The vendored C is never what we are debugging, and at -O0 it dominates // the app: 90% of a Debug startup is tree-sitter's query analyser // (perf: ts_query__perform_analysis + ts_lookahead_iterator__next), and |
