Status: done (2026-11-15)
Priority: 2
Size: S
Arch: between
Phase: implement
Design ref: none (code structure). Survey and measurements: backlog/VB-242.md.
Goal: heirRanking (src/sim/heirs.js:20-90) has seven parameters, and two of them serve only the round’s cache, roundHeirs (heirs.js:103-147). watch records which rankings depend on which pawns and spouses. family reuses a household’s line while hh.members is the same array of the same length, which leans on how moveTo replaces one array and appends to the other. After VB-277 the marriages rank afresh in each village’s step; the view is still built by the round’s demand phase (countDemand(st, roundHeirs(st).rank), lifecycle.js:149), by an offer’s close for its handover (closeOffer, lifecycle.js:320), and by matchRules (src/sim/matching.js:7, :33) unless VB-277 has made it rank afresh; matchRules also serves the player’s wish (matchBar, VB-274) and its options (sim/opportunities). Remove the cache.
Acceptance criteria:
roundHeirs and its invalidate go, with heirRanking’s watch and family parameters and the code that serves them (heirs.js:32-36, 60-62, and the watch call in the filter). The demand phase calls countDemand(st), which ranks through its own ownFirstOf(st), as the scenarios and the drawer do. matchRules (and with it matchBar and sim/opportunities) and closeOffer’s handover no longer read the view; tests/wishes.js and tests/offers.js pass.nested is the direct-heirs-only ranking that ownFirstOf needs for the rule “an heir to their own parents’ farm” (heirs.js:73-89); it is a rule, not a cache. ownFirstSet is the whole-island view of first direct heirs that a pass computes once while nothing changes (countDemand, firstHeirs, placeIfMarried, refreshInterests until VB-278). It has no dependencies to track, and tests/lib/heir-rankings.js (VB-224) checks the candidate-lines shortcut against it. Measured by VB-242, ranking every household without it costs 2.6 to 4.3 ms at medium-ref (574 rankings) against 5.5 to 19 ms with it (422), and 16 to 23 against 12 to 27 ms at small-y40 (1,109 against 338), so it saves nothing worth a parameter. It is kept only as the test’s reference and a pass’s shortcut. heirRanking(st, hh, cust, nested, ownFirstSet): five parameters, not seven.countDemand’s rank parameter and placeIfMarried’s, and their callers’ plumbing, go if nothing passes them after VB-277. Otherwise the PR names who still does.tests/marriage.js (lines 90 to 125 at fd74348: the view against fresh rankings across commands) goes with the cache. tests/counters.js keeps roundRank, now the rankings of the round’s day; tools/moving-profile.js and the rest of tests/marriage.js (today the only places outside src/ that name roundHeirs; tests/heirs.js and tests/fixtures.js no longer do) are brought in line.BACKLOG.md: behaviour unchanged (node tools/same.js --base REF prints same), and the hard checks pass. tests/counters.json is re-recorded only if heirRank or roundRank move, which happens only if the demand phase now ranks a different number of times, and the PR lists them.medium-ref and small-y40 within 60 ms. countDemand without the view took 5 to 13 ms (VB-242).matchRules in sim/matching.js, which serves matchBar, and closeOffer’s handover), the demand phase’s line refreshed, and VB-293 (done) dropped from the order note.nested, ownFirstSet) and why. The measurement at fb35e75 in VB-242’s notes found the cache and a fresh ranking give the same final state.sim/heirs.js, sim/lifecycle.js and sim/matching.js: one at a time with VB-277, VB-278 and VB-288 (which edits matchScore in sim/matching.js).src/sim/heirs.js after it.roundHeirs (with invalidate, the dependents map and the family memo), heirRanking’s watch and family, and the rank parameter of countDemand, placeIfMarried, staysWhy, wantsOut; nothing passed rank after VB-277/278 but the demand phase. matchRules and closeOffer already ranked afresh. opportunities passed an explicit wish=null positionally; adjusted.nested (a rule: direct heirs only, for ownFirstOf) and ownFirstSet (a pass’s shortcut with no dependencies to track, reference of tests/lib/heir-rankings.js). heirRanking(st, hh, cust, nested, ownFirstSet).tests/marriage.js and the roundHeirs wrap in tools/moving-profile.js removed.same.js --base 32973d2 prints same (founders, heirs, seeds 7 and 42, tiny, 2 years). tests/counters.js: heirRank and roundRank 0.02228/pawn-day, equal to before; counters.json not re-recorded. verify 111/111. Fell: 19 insertions, 157 deletions over 5 files, two parameters, and the dependence on events naming every household a command changed.