village-builder

VB-199: Bounded history: a pawn’s events as an index, routine events folded

Status: done (2026-11-10) Priority: 2 Size: M Arch: yardstick Phase: implement Design ref: People, households and family records. docs/roadmap.md, sections 5.2 (save and load under 0.5 s each, Decided, Kim, 3 November), 5.3 (rule 9, bound history) and 5.4; VB-075 (the record of events). Goal: History grows without bound, and the save with it. Measured on 3 November, populous small at seed 7:

Implementation, 10 November 2026

Impact note. Modules: sim/records writes the record, pawn.events (now positions in st.record), and the two new state fields st.recordYears (the folded counts, {year, kind, village, tally}) and st.recordFold (the fold’s positions and its pass in progress), all three given to sim/records in src/owners.json. HISTORY (beside record) is the one table of kinds: 0 keeps a kind, otherwise the years after which it is folded (friend, fellOut 2; the other routine kinds 25). foldHistory runs daily from sim/clock (hour 0): at the year’s turn it walks from its two cursors to the first event too young (the record is appended in time order), then folds a village a day, then the events of no village; a folded slot becomes the index of its count, so no position ever moves (the notices’ and the skip’s cursors, the history tab’s stamp and the pawns’ positions stay good). personEvent writes one record event and pushes its position; with false its event is the pawn’s own telling (self: true, with the pawn’s village), which only the pawn’s life reads: notable, skipStop, chronicle, villageLog, recordOf and the round’s changedSince (sim/lifecycle, so the run is unchanged) skip it. Births and deaths point to the log’s event (lifeEvent; log now returns the position). recordOf moved from sim/records to sim/notable, which has CAUSES: Sim.recordOf(st, {pawn, life: true}) (lifeOf) gives a pawn’s life in its own words (a death as “Died of …”, a birth with no text, as the copies had; a folded one as {kind, folded: tally}), read by the family panel (src/page/family.js) and by the tools and tests that read p.events. friend/fellOut events now carry the pawn’s village (sim/relations), so they fold by village. sim/saves calls indexEvents on load: an older save’s copies become positions (matched by pawn, time and text; a birth or death by kind), and a copy told beside another is appended as a self event, but for routine ones (gifts given), which are dropped. New coupling: sim/clock calls foldHistory; nothing else. New counter recordFold (slots passed by the fold; 0 in the 30-day counter and scaling fixtures, which reach no year’s turn). tests/lib/fixtures.js accepts a record longer than the stamp (the appended self events). Behaviour: unchanged. Every state key but pawns, cenv (which holds the pawns), record and the two new ones hashes as at 7812253 (founders and heirs at seed 7, 3 years, pawn events and self events taken out).

Validation, 10 November 2026

  small-y40 before after medium-ref before after
JSON, MB 29.4 13.0 31.8 20.4
gzip, MB 5.13 3.15 6.15 4.83
pawns, MB (their events) 13.8 (8.43) 6.01 (0.60) 16.9 (6.29) 11.0 (0.44)
record, MB (events in full / slots) 12.3 (108,852) 3.65 (25,458 / 111,791) 9.20 (82,192) 3.69 (28,595 / 84,068)
recordYears, MB   0.06 (1,171 counts)   0.001 (22)
encode + stringify, ms 438 + 185 = 623 253 + 96 = 349 628 + 241 = 869 431 + 171 = 602
gzip, ms 423 231 656 372
parse + decode, ms 142 + 160 = 302 63 + 97 = 160 182 + 218 = 400 119 + 155 = 274

Load is under the 0.5 s line at medium-ref (274 ms); the save’s main thread is not (602 ms, down 31%). What is left is mostly the pawn records without their events (10.6 MB at medium-ref: relations, attitudes, ties) and the rest of the state (5.7 MB); the record is 3.7 MB, of which the folded slots about 0.3 MB. Next step, VB-226’s (not built here): pawn records in columns, or the save encoded from a structured clone in a worker (roadmap 5.5); the folded slots could later be dropped by remapping positions, if they matter.