Status: done (2026-11-10)
Priority: 2
Size: M
Arch: yardstick
Phase: implement
Design ref: none (code structure). docs/roadmap.md, section 5.3 (rules 4, 5 and 6); docs/bench/closure.md (VB-203).
Goal: At medium-ref, “jobs refresh and matching” (refreshJobs, callCooks, lookUp and planRound in tools/perf.js) costs 35.1 ms a game day, the mean of three whole-year runs on 9 November at 9f130e6 (33.2 to 36.5), against its share of 30 ms (VB-203, docs/bench/closure.md). Spring costs most: 47.5 ms a day in one run, against 30 to 34 in the other seasons. Find which entry point and loop carry it, and cut it to the share.
Acceptance criteria:
medium-ref and small-y40, a whole game year each: the ms a game day of each of the four entry points, by season, and a CPU profile (node --cpu-prof) of the largest.VB.COUNTERS), asserted at tiny scale in tests/counters.json.tools/sim.js before and after at seeds 7 and 42.medium-ref (tools/bench.js, whole year), paired runs before and after, and the counters; the residual reported, with the task or docs/bench/closure.md line that closes what is left.npm run verify’s hard checks pass, its targets reported with their residuals.
Notes:KINDS record: the two edit the same code, and a cost cut is clearer per kind.7b267af + this branch): the share is not reached by order-preserving cuts alone; criteria 3 and 4 are
left open, with the gap below, for VB-248 and VB-249 (explicit targets, reviews in windows and a due-queue on planning days).Impact note: no new module, state field or coupling. sim/jobs’ review builds builtTiles once at the hour of the land looks and hands it
to startProject and startMeadow (sim/fields, sim/meadows: an optional last argument of chooseTile and chooseMeadow); meadowJobs
(sim/meadows) takes want as a boolean or a function asked only when a raking or mowing could be posted; byreJobs (sim/byre) walks
hh.herds without building arrays and counts the cows in milk only when a milking could be posted; jobsFor returns the household’s or
the village’s set as it stands when the other is empty; dailyNeed and larderOf (sim/hunger) are loops, summing in the same order.
Three work counters: matchBid, lookUpJob, cookFarm. tests/golden.json unchanged.
Measurements (a scratch loader that wraps the four entry points one by one, whole game year of 48 days from the fixture, wall ms a game day; the machine is noisy: the whole simulation varied 146 to 211 ms a day between runs of the same code, so each pair is also given as the line’s share of the whole step).
medium-ref (4 runs, 28.6 to 31.9, mean 30.05 ms; spring/summer/autumn/winter 37.7/29.7/29.6/23.3):
refreshJobs 13.50 (16.1/12.1/13.4/12.4), planRound 13.18 (15.9/14.1/13.7/9.0), lookUp 2.62 (4.7/2.8/1.9/1.1), callCooks 0.75.
small-y40 (2 runs, 15.4 to 16.0, mean 15.71): refreshJobs 7.05 (9.1/6.2/7.0/5.9), planRound 6.44 (8.3/6.2/6.6/4.7), lookUp 1.60
(3.0/1.3/1.3/0.8), callCooks 0.61. Spring is dearest at both: the review’s sowing, raking and new jobs, and twice the looking up.node --cpu-prof, medium-ref, of refreshJobs and planRound, the two largest at about 45% each): in the review, post and
the rules’ closures (35%), the byre’s and meadows’ rules (byreJobs, meadowWork, hayWanted: 28%), and the land looks at 06:00
(builtTiles rebuilt per farm, farms times farms a day, chooseTile, bfs: 20%; the 06:00 review costs 3.0 ms against 0.5 for other
hours); larderOf and dailyNeed’s map/filter/reduce (16% with inlining off). In matching: planRound’s own bidding and sort (30%),
jobsFor (two key strings and a merge per idle pawn, 15 to 18%), and the routes the issued work walks (route’s LRU, findRoute,
walkTo: about 35%, sim/routes, not changed here).planReview, oppAsk, VB-258); matching weighs each idle pawn with
its jobs (matchBid, 9.63 per living pawn-day at tiny scale, 11.7 at medium-ref), looking up weighs each working pawn with its jobs
(lookUpJob, 5.66; 4.38), and callCooks walks every farmstead from 14:00 (cookFarm, 0.80; 0.86). tests/counters.json gains these
three only (the other entries are identical at base and branch and left as they were). tests/history.js: matchBid 0.664 and lookUpJob
0.744 from small-y5 to small-y40, cookFarm 1.386, over the 1.25 line like planReview (1.342): per holder, and households per living
pawn grow over history; recorded as its ceiling in the history section of tests/cost-baseline.json, as VB-258 did.medium-ref, paired with before and alternated (two sets): set 1, before 30.05 (28.6 to 31.9) and after 27.93 (23.8 to 31.1),
share 17.07% and 16.04%; set 2 (final code), before 32.17 (29.6 to 33.5) and after 29.65 (23.7 to 35.5), share 17.37% and 16.20%.
refreshJobs falls by about 15% (11.25 against 13.50 in set 1; share 7.6% to 6.4%); planRound, lookUp and callCooks are unchanged within
the noise. small-y40 (2 pairs): 15.71 (15.4 to 16.0) before, 14.89 (14.6 to 15.2) after; refreshJobs 7.05 to 6.06.tools/bench.js (whole year, medium-ref, paired and alternated, 3 each, twice): before 26.39, 25.11, 28.09 and 34.66, 27.96, 27.27
(mean 28.2, 25.1 to 34.7); after 30.58, 27.20, 25.46 and 32.78, 30.65, 25.41 (mean 28.7, 25.4 to 32.8); the line’s share of the whole
simulation 16.9 to 17.2% before and 15.9 to 16.3% after. This machine runs about 15% faster than on 9 November (before: 35.1); on
that scale the cut takes the line from 35.1 to about 33, not to 30. Counters unchanged by the cuts but for the three new ones.QUESTIONS.md (“VB-227”).Validation (10 Nov 2026): npm test (86 scripts) and node tests/golden.js (unchanged) pass; npm run verify’s hard checks pass, its targets reported with their residuals but for
tests/history.js, which fails at 7b267af too, on fresh fixtures, with the same seven values: routeExpand 1.462, routeRefresh 1.856,
walkTies 1.436, roundPairs 10.24, heirRank 1.596, roundRank 1.480, and recordFold 1.558 (also failing at base, not in the six listed).
No behaviour changes: households are exactly as before.
7205992 on fresh fixtures, three runs of tools/bench.js in a row, jobs refresh and matching reads 26.4 ms a game day at medium-ref (26.0 to 27.2), 16.0% of the day’s 164.8: in, under its share of 30. At medium-y5 23.4 (20.5 to 25.3). The line this task was written for is met on this machine today; Kim’s question on VB-227 decides whether it closes.QUESTION_ARCHIVE.md, VB-227): closed with its order-preserving cuts. Residual: jobs refresh and matching about 33 ms a game day at medium-ref against 30 (about +3). The 30 ms target, judged by share in paired runs, is now a criterion of VB-249, whose planning days and due-queue take the review off its hourly pass.