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:
tests/scaling.js in npm test, under 5 s: tiny worlds (tests/lib/tiny.js) with 2 and with 4 identical villages side by side (the same map strip repeated, the same household sizes), 30 game days and one moving round each. For each counter, the exponent log(W4 / W2) / log(N4 / N2) of its work against the living. Over 1.15 fails.tests/history.js in npm run verify, under 30 s: from small-y5 and small-y40 (VB-193, through loadFixture), 30 game days and one moving round each. For each counter, its work per living pawn-day at year 40 against year 5; over 1.25 (the budget’s line) fails. It runs on a stale fixture, saying so, and skips with a notice when there is none.Sim.advance(st, 0.1), timed in the test, since modules read no clock) and prints the longest, the 99th percentile and the hour of the five longest; reported, never failing (timing belongs to the bench, VB-194).tests/cost-baseline.json, as the lint keeps its baseline: an entry per counter and check, which may only go down (--update lowers it); a counter without an entry must pass. Expected today: the walks over the dead (walkStep, walkDaily), the moving round’s rankings (roundRank) and, in the scaling check, its pairs (roundPairs, quadratic across villages). VB-195 and VB-196 lower them.node tests/run.js verify --verbose).HEAD in this file.ready.
Cost: about 5 s in npm test and 30 s in verify, in parallel with the other scripts.
Notes:tests/perf.js (6-minute steps timed one by one, mean/worst day, budgets as above) reports populous medium seed 7 over 2 years: 135 ms/day mean (passes, budget 500), worst day 1217 ms, but the longest single step is 1016 ms (year 1 summer… season 2 day 10, 12:00, the moving round; meetings step 75 ms) against a limit of 100 ms. Adding the check to verify would fail it at once. Kim: raise the step budget for the yearly moving round, exempt it, or make VB-task to split the round over several steps.ready. For the step limit, take the worst step of the median of 3 runs or the 99th percentile of steps, whichever stays clear of garbage-collector pauses, and say which in the PR. VB-127 uses this test for its cost criterion.docs/roadmap.md, sections 3.0 and 6): to be rewritten as part of slice 0, the yardstick: deterministic work counters asserted at tiny scale, a scaling check, and a late-game fixture loaded from a save, with wall-clock timing reported nightly. Measured that day: one year from a year-40 save of populous small costs 227 ms a game day, and its moving round takes 899 ms in one call, which a run of populous medium at year 2 cannot show. Waits for Kim’s answers to the roadmap’s questions (QUESTIONS.md, Priority 1).docs/roadmap.md, section 3.0; the slices Decided by Kim): moved to slice 0, arch yardstick (from tooling).3 Nov 2026 (VB-181, the plan of slice 0): rewritten around counters and fixtures, as the roadmap asks. The old criteria (ms per game day and per step in verify, failing above twice the budget) are dropped: wall-clock timing moves to the nightly bench (VB-194), which reports and never fails. blocked until VB-192 and VB-193 are done. Measured for the plan, populous small at seed 7, 30 game days from saves: 0.304 ms per living pawn-day at year 5 and 0.351 at year 40 (1.15 times), without the moving round, which took 37 ms at year 5 and 485 ms at year 40.
fixtures branch.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.
tests/scaling.js runs in test and verify: two/four repeated 28-by-28 terrain strips, three farms per village,
six people per household, identical farm geometry and family age/sex patterns. The layout is asserted equal.
Mean living populations are 36 and 72. Every declared counter and the derived roundRank is exercised.tests/history.js runs in verify: fresh small-y5 and small-y40 fixtures stamped 4df5766, each with
one explicit moving round at the saved hour, then 30 days (7,200 six-minute calls). The windows end before
the next scheduled moving round. Living pawn-days are integrated from birth/death times: 11,704.5 / 21,781.
Stale fixtures are identified and used; missing fixtures skip the comparison; incompatible formats fail.tests/cost-baseline.json records only measured excesses. Both scripts accept --update to lower existing
entries and remove fixed ones; a new excess or an increased one fails without writing the file.
tests/cost-rules.js exercises that policy, non-finite/zero work, coverage and linear/quadratic growth.| 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.