village-builder

VB-227: Jobs: refresh and matching within their share

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:

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).

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.