Status: done
Priority: 1
Size: S
Arch: yardstick
Phase: implement
Design ref: none (measurement). docs/roadmap.md, sections 5.2 (the budget and its table, Decided, Kim, 3 November) and 6 (bench history, microbenchmarks).
Goal: The counters catch extra work, but they do not show what a game day costs on a real machine, and they do not show slow drift over many commits. A nightly bench on the two medium fixtures does both. It is appended to a history and never fails. The budget table shows each system and each measure against its line, so every slice’s plan can name its line and its wrap-up can measure it. Blocked until VB-193 (the fixtures) is done.
Acceptance criteria:
tools/bench.js runs on medium-y5 and medium-y60 (VB-193). For each, it calls the moving round and the meetings once (timed, one call each), then advances 30 game days, timing each 6-minute step from the tool. It reports:
Sim.save, JSON.stringify and gzip, each), MB of JSON and gzipped, and load time (parse and Sim.load);tools/perf.js divides them.findRoute) on 1,000 random reachable pairs of tiles of the medium map, in µs per search and ns per expanded tile. The rules registry (VB-197) adds Rules.value in ns per call.docs/bench/history.jsonl: date, commit, Node version, CPU model and cores, the fixtures’ stamps, and the numbers above. A number 20% or more worse than the median of the last five lines on the same CPU model is flagged in the output (FLAG, with the five values). The tool always exits 0.docs/bench/budget.md, written by tools/bench.js --budget from the last history line, never edited by hand. One row per measure of the budget (docs/roadmap.md, section 5.2) and one per system, with its budget (blank until a plan sets one), year 5 and year 60. The ratio of ms per living pawn-day at year 60 to year 5 is the budget’s flat-in-history line. A slice’s plan adds its system’s budget to a table at the top of tools/bench.js.tools/nightly.js (VB-193) runs the bench after the fixtures. The nightly run commits the history line and the table in its PR.3 Nov 2026 (VB-181, the plan of slice 0): written; blocked until VB-193 is done. The early reference of the budget table is year 5, where the flat-in-history ratio starts; tests/perf.js keeps year 2 for a quick check by hand. One hook in the clock that times every step waits for the declared calendar (target-v2, section 3.3, slice 3); until then the tool times Sim.advance in 6-minute calls and tools/perf.js keeps its list of systems.
fixtures branch.Impact: reads the medium fixture states, simulation APIs, rules registry and work counters in Node tooling. Writes only bench history and its generated budget table. Adds the nightly-to-bench call and a profiler reset; no simulation state, owner, random stream or gameplay rule changes. Measurement remains outside src/.
Validation: VB_TEST_JOBS=2 VB_CHROMIUM=/usr/bin/chromium VB_SOFTWARE_RENDER=1 npm run verify passed all 80 scripts in 273.7 s after the PR review fix. node tests/bench.js also passes after the final reporting changes. Rebuilt index.html; it, tests/golden.json, tests/counters.json and the cost baseline are unchanged. The nightly hook was added without running fixture publication as part of this task.
Review before PR, 5 November 2026: an interrupted final JSONL line could absorb the next result. Appends now insert a separator when needed, preserving the partial entry for diagnosis and keeping subsequent results readable. Regression coverage includes a missing final newline, a partial entry, repeated appends and a fresh history file.
First baseline: both compatible fixtures have stale golden hashes after VB-159. Their stamps and starting populations (880 and 2,492) remain visible. The late reference exceeds the roadmap’s approximate 1,000 living. These are diagnostic measurements on the stored states, not regenerated populations. There are no five-run medians yet. History records the base commit plus a dirty working-tree marker because the first measurement preceded the implementation commit.
The year-60 run costs 752.525 ms/day; the moving round takes 17,183.510 ms; save/stringify/gzip takes 6,016.713 ms, parse/load 1,567.307 ms, and gzip is 24.555 MB. Cost per living pawn-day grows 1.268 times. These existing budget overruns inform VB-195, VB-196, VB-127, VB-198, VB-199 and VB-201; this measurement task does not tune them.
First history entry (docs/bench/history.jsonl):
{"schema":1,"date":"2026-11-05T19:37:22.066Z","commit":"7953b554e2b5de9e9d8f5f987c30bdbe75548b23","dirty":true,"node":"v24.22.1","cpu":{"model":"INTEL(R) XEON(R) PLATINUM 8573C","cores":3},"fixtures":{"medium-y5":{"stamp":{"name":"medium-y5","commit":"4df576663f12ecd23f432413f1709d4f260c6f6d","format":1,"goldenHash":"d22c1855f83228c6bd4a7be69adefe169d249e097f9f7da821bfdc0433769c54","year":5,"living":880,"pawnRecords":975,"events":32698,"minutes":3.7748333333333335,"jsonBytes":18212168,"gzipBytes":3634501,"saveHash":"25a0a699d3270c0f031db3b02d4afd86ed14dcd6bbb9ea8e8a99e518a3bc5582"},"stale":true,"days":30,"from":5766.000000003206,"to":6486.000000005825,"pawnDays":26747.50000009729,"meanLiving":891.5833333365764,"msPerDay":211.66436886651596,"msPerPawnDay":0.23740278777352583,"longestMs":187.483678999939,"p99Ms":8.633352000033483,"longest":[{"hour":5783.900000003271,"ms":187.483678999939},{"hour":5807.900000003358,"ms":108.20620000001509},{"hour":6047.9000000042315,"ms":105.20236399990972},{"hour":6335.900000005279,"ms":104.68768600001931},{"hour":6287.900000005105,"ms":99.86603999999352}],"movingRoundMs":145.26568999999995,"meetingsMs":32.44366799999989,"heapMB":193.458176,"saveMs":403.8502530000005,"stringifyMs":298.52198399999907,"gzipMs":389.11449100000027,"saveTotalMs":1091.4867279999999,"jsonMB":19.212953,"gzipMB":3.854049,"parseMs":193.92117300000064,"loadMs":127.80752500000017,"loadTotalMs":321.7286980000008,"systems":[{"system":"talk and contacts","ms":1740.6,"msPerDay":58.02,"share":27.4,"calls":1440,"longestMs":12.25,"longestCall":"talkHour"},{"system":"agents and walking (the rest of Sim.advance)","ms":1735.1,"msPerDay":57.84,"share":27.3,"calls":0,"longestMs":0,"longestCall":""},{"system":"daily life and births","ms":1692.9,"msPerDay":56.43,"share":26.7,"calls":60,"longestMs":168.37,"longestCall":"dailyLife"},{"system":"jobs refresh and matching","ms":983,"msPerDay":32.77,"share":15.5,"calls":4324,"longestMs":17.54,"longestCall":"planRound"},{"system":"paths and routes","ms":106.2,"msPerDay":3.54,"share":1.7,"calls":60,"longestMs":14.17,"longestCall":"refreshRoutes"},{"system":"hunger and meals","ms":60,"msPerDay":2,"share":0.9,"calls":11156,"longestMs":2.24,"longestCall":"feedHousehold"},{"system":"byre","ms":21.7,"msPerDay":0.72,"share":0.3,"calls":30,"longestMs":4.2,"longestCall":"byreDay"},{"system":"herds","ms":8.7,"msPerDay":0.29,"share":0.1,"calls":30,"longestMs":7.68,"longestCall":"herdsDay"},{"system":"meadows","ms":1,"msPerDay":0.03,"share":0,"calls":30,"longestMs":0.21,"longestCall":"meadowsDay"},{"system":"trees","ms":0.7,"msPerDay":0.02,"share":0,"calls":30,"longestMs":0.14,"longestCall":"growTrees"},{"system":"the moving round","ms":0,"msPerDay":0,"share":0,"calls":0,"longestMs":0,"longestCall":""},{"system":"meetings","ms":0,"msPerDay":0,"share":0,"calls":0,"longestMs":0,"longestCall":""}],"micro":{"routeSearches":1000,"routeExpanded":4170112,"routeUs":1575.873117000001,"routeNsPerExpanded":377.8970725486512,"rule":"death.hazard","ruleCalls":1000000,"ruleNs":116.1524870000012,"ruleChecksum":357.3304180489611,"routeMaxCost":"unbounded (reachable components)"}},"medium-y60":{"stamp":{"name":"medium-y60","commit":"4df576663f12ecd23f432413f1709d4f260c6f6d","format":1,"goldenHash":"d22c1855f83228c6bd4a7be69adefe169d249e097f9f7da821bfdc0433769c54","year":60,"living":2492,"pawnRecords":4814,"events":505530,"minutes":59.23936666666667,"jsonBytes":133615488,"gzipBytes":23944308,"saveHash":"9f4ec9dba0d5cda41bca4026ca0e4690ae37ab2b14e49384788491836234f07f"},"stale":true,"days":30,"from":69125.99999953299,"to":69845.9999995749,"pawnDays":74990.17917103169,"meanLiving":2499.6726390343897,"msPerDay":752.5251478333802,"msPerPawnDay":0.3010494798727231,"longestMs":393.653699999908,"p99Ms":28.69786800001748,"longest":[{"hour":69407.9999995494,"ms":393.653699999908},{"hour":69143.99999953403,"ms":386.9660579999909},{"hour":69263.99999954102,"ms":247.90031900000758},{"hour":69455.9999995522,"ms":244.0380100000184},{"hour":69215.99999953822,"ms":232.06627700000536}],"movingRoundMs":17183.510021,"meetingsMs":293.3858619999992,"heapMB":778.356184,"saveMs":1970.1586160000006,"stringifyMs":1185.2077019999997,"gzipMs":2861.346360000003,"saveTotalMs":6016.7126780000035,"jsonMB":136.331496,"gzipMB":24.554745,"parseMs":726.6920270000046,"loadMs":840.6146819999994,"loadTotalMs":1567.306709000004,"systems":[{"system":"agents and walking (the rest of Sim.advance)","ms":7993.9,"msPerDay":266.46,"share":35.4,"calls":0,"longestMs":0,"longestCall":""},{"system":"talk and contacts","ms":6179.3,"msPerDay":205.98,"share":27.4,"calls":1440,"longestMs":76.81,"longestCall":"noteContacts"},{"system":"daily life and births","ms":4838.4,"msPerDay":161.28,"share":21.4,"calls":60,"longestMs":336.17,"longestCall":"dailyLife"},{"system":"jobs refresh and matching","ms":2649.3,"msPerDay":88.31,"share":11.7,"calls":4318,"longestMs":33.02,"longestCall":"planRound"},{"system":"paths and routes","ms":661.7,"msPerDay":22.06,"share":2.9,"calls":60,"longestMs":48.48,"longestCall":"refreshRoutes"},{"system":"hunger and meals","ms":216.9,"msPerDay":7.23,"share":1,"calls":37312,"longestMs":8.47,"longestCall":"shareFood"},{"system":"byre","ms":23.3,"msPerDay":0.78,"share":0.1,"calls":30,"longestMs":3.55,"longestCall":"byreDay"},{"system":"herds","ms":10.1,"msPerDay":0.34,"share":0,"calls":30,"longestMs":9.17,"longestCall":"herdsDay"},{"system":"meadows","ms":2.2,"msPerDay":0.07,"share":0,"calls":30,"longestMs":0.29,"longestCall":"meadowsDay"},{"system":"trees","ms":0.7,"msPerDay":0.02,"share":0,"calls":30,"longestMs":0.13,"longestCall":"growTrees"},{"system":"the moving round","ms":0,"msPerDay":0,"share":0,"calls":0,"longestMs":0,"longestCall":""},{"system":"meetings","ms":0,"msPerDay":0,"share":0,"calls":0,"longestMs":0,"longestCall":""}],"micro":{"routeSearches":1000,"routeExpanded":4011558,"routeUs":1692.1852619999993,"routeNsPerExpanded":421.82744509739086,"rule":"death.hazard","ruleCalls":1000000,"ruleNs":115.06795300000522,"ruleChecksum":1549.1785556485604,"routeMaxCost":"unbounded (reachable components)"}}},"flags":[]}
First generated budget table (node tools/bench.js --budget):
Generated by node tools/bench.js --budget; do not edit by hand.
Measured 2026-11-05T19:37:22.066Z; commit 7953b554e2b5de9e9d8f5f987c30bdbe75548b23 (working tree changes); v24.22.1; INTEL(R) XEON(R) PLATINUM 8573C (3 cores).
medium-y5: stale golden hash, 880 starting living, stamp 4df576663f12ecd23f432413f1709d4f260c6f6d.
medium-y60: stale golden hash, 2492 starting living, stamp 4df576663f12ecd23f432413f1709d4f260c6f6d.
| Measure | Budget | Year 5 | Year 60 |
|---|---|---|---|
| Mean simulation (ms/day) | 160; ceiling 400 | 211.664 | 752.525 |
| Longest 6-minute step (ms) | 50 | 187.484 | 393.654 |
| 99th percentile step (ms) | 8.633 | 28.698 | |
| Simulation (ms/living pawn-day) | 0.237 | 0.301 | |
| Moving round, one call (ms) | 50 step limit | 145.266 | 17183.510 |
| Meetings, one call (ms) | 50 step limit | 32.444 | 293.386 |
| Save + stringify + gzip (ms) | 500 | 1091.487 | 6016.713 |
| Parse + load (ms) | 500 | 321.729 | 1567.307 |
| JSON (MB) | 19.213 | 136.331 | |
| Gzip (MB) | 10 | 3.854 | 24.555 |
| Heap after window (MB) | 193.458 | 778.356 | |
| Cost per living pawn-day / year 5 | ≤1.25× | 1.000 | 1.268 |
| Page frames | Deferred (VB-166) | — | — |
| agents and walking (the rest of Sim.advance) (ms/day) | 57.840 | 266.460 | |
| byre (ms/day) | 0.720 | 0.780 | |
| daily life and births (ms/day) | 56.430 | 161.280 | |
| herds (ms/day) | 0.290 | 0.340 | |
| hunger and meals (ms/day) | 2.000 | 7.230 | |
| jobs refresh and matching (ms/day) | 32.770 | 88.310 | |
| meadows (ms/day) | 0.030 | 0.070 | |
| meetings (ms/day) | 0.000 | 0.000 | |
| paths and routes (ms/day) | 3.540 | 22.060 | |
| talk and contacts (ms/day) | 58.020 | 205.980 | |
| the moving round (ms/day) | 0.000 | 0.000 | |
| trees (ms/day) | 0.020 | 0.020 |
30 days, 6-minute calls; exclusive system timings include profiling overhead. Explicit round and meeting calls are outside the daily mean.
Heap is used heap without forced GC. Save/load totals include the listed codec stages; load excludes world generation and disk IO.
Fixture stamps, staleness, five longest step hours, codec stages and microbenchmarks are in history.jsonl.