village-builder

VB-088: A cost budget in the test runs: scaling and history checks

Status: done Priority: 1 Size: S Arch: yardstick Phase: implement Design ref: none (measurement). docs/roadmap.md, sections 5.2 (the budget: cost per living pawn-day at year 60 at most 1.25 times year 5) and 6 (scaling exponent, history check); AGENTS.md, Rules for cost, rules 1 and 2. Goal: Performance is measured once per task, by hand. This task first asked for wall-clock timing in the verify run, but timing at year 2 missed the late game, and timing flakes. Check work instead, from the counters (VB-192): how it grows with the number of people (scaling) and with history (year 5 against year 40). Then rules 1 and 2 of the Rules for cost are tested in every run, and a loop over the dead or over pairs fails when it is added. Blocked until VB-192 (the counters) and VB-193 (the fixtures) are done. Acceptance criteria:

Implementation, 5 November 2026

Impact: tests and test helpers only; no simulation, page, saved state, golden state or work-counter changes. tests/lib/cost.js reads VB.count and pawn lifetimes; the simulation never reads these measurements. The history windows use isolated workers, one per fixture, to meet the 30-second cost target. Only the parent may fetch fixtures; neither worker writes them. No new coupling between simulation systems.

Counter Scaling exponent (limit 1.15) History ratio (limit 1.25)
routeSearch 1.059854 0.807138
routeExpand 1.183979 0.825326
routeHit 1.022823 0.934905
routeRefresh 1.740393 1.820950
talkWeighed 0.996243 0.934606
contactPairs 0.960710 0.796365
walkStep 1.000000 1.583676
walkDaily 1.000000 1.495102
walkTies 1.009199 1.126248
roundPairs 2.000000 2.619689
heirRank 1.000000 2.317458
ruleValue 1.000000 1.000128
roundRank 1.000000 2.287144

Wall-clock timings remain reports only, including the longest step, p99 and hours of the five longest steps for each save. The deterministic ratios above are the same in serial and isolated-worker runs.

Runtime on this two-core runner, standalone: scaling about 2 seconds; history 21.1 seconds, including both worlds generated and saves loaded. Wall times under suite contention vary; no timing threshold is asserted.

Validation: npm run verify -- --verbose passed all 78 scripts, including all four saved fixtures, golden state, counter snapshots, ownership, invariants, saves, jsdom, and both Chromium checks (786 s total on this runner). The existing Chromium click actions needed a 120-second timeout, set only through a scratch preload for software rendering; their assertions were unchanged. python3 build.py was run; src/, index.html, tests/golden.json and tests/counters.json remain byte-for-byte unchanged.