// Guards against top-level work creeping back into runtime.js: digest.ts's eager SHA // constant tables (sketches/lazy-builtins.md) went unnoticed for a while because nothing // measured module evaluation apart from compile. scripts/eval-budget.mjs compiles and // evaluates the built bundle with node:vm (median of 40 rounds) and this test fails when // evaluate takes too large a share of that time. // // Budget: 0.3. Measured medians (Node 24.16, this machine, vm.SourceTextModule): the // current runtime.js (digest tables built lazily) is at ratio ~0.20; reverting just // digest.ts to eager tables (the state before this fix, at Node main 8a3c0df) raises it // to ~0.35. 0.3 sits with headroom below the regression and above measurement noise // (the medians above vary by <0.01 across repeated runs on an idle machine), so a loaded // CI box shouldn't flip it, but a new eager top-level cost of digest.ts's size or larger // will. import { execFileSync } from "node:child_process"; import { test, expect } from "@playwright/test"; const BUDGET = 0.3; test("runtime.js evaluation stays a small share of its compile time (no new eager top-level work)", () => { const out = execFileSync( process.execPath, ["--experimental-vm-modules", "scripts/eval-budget.mjs", "dist/runtime/runtime.js"], { encoding: "utf8" }, ); const { compileMs, evaluateMs, ratio } = JSON.parse(out.trim().split("\n").pop()!); expect(ratio, `compile ${compileMs.toFixed(2)}ms, evaluate ${evaluateMs.toFixed(2)}ms, ratio ${ratio.toFixed(3)}`).toBeLessThan(BUDGET); });