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:
st.record holds 110,278 events, and 81% of them are friend (52,201) and fellOut (36,598);QUESTION_ARCHIVE.md, “VB-199: bounded history”):friend, fellOut, gift, harvest, hay, frost, herdBirths, herdDeath, slaughter, spoiled and putOff. A kind in neither list is notable until a task says otherwise; the two lists are one table beside the record’s kinds, and tests/record.js checks every kind is in it.friend and fellOut fold 2 years after they were written; the other routine kinds after a generation (25 years).st.record (the event’s position), not copies: personEvent writes one record event and pushes its index. The pawn panel and the family tree read them through Sim.recordOf, and a pawn’s life reads the same before and after (a test compares the texts).st.recordYears, at the ages decided above; notable events stay in full. Folding runs at the year’s turn, spread over the year’s first days a village at a time (rule 5). An index whose event was folded points to its count.small-y40 and medium-ref, each part (encode, stringify, gzip; parse, decode), with the MB before and after. The line is Kim’s (9 November): 0.5 s of main thread each at medium-ref, encode + stringify for the save; what size alone cannot reach is VB-226’s.tests/record.js, tests/saves.js and tests/codec.js pass; the new state field has its invariants in checkState.medium-y60; 1.0 s and 0.29 s at medium-y5 (node tools/bench.js on 6eaa6bc, with fixtures made before VB-174’s ledgers). The late reference becomes medium-ref (VB-202, about 1,000 living), and VB-203 may rewrite the fixtures this task’s criteria name. VB-204 folds the food ledgers, which VB-174 grew to about 200 entries per household-year; this task keeps to st.record and pawn events.medium-ref. Until VB-203 rewrites this task, measure on medium-ref as well as small-y40.medium-ref on 9 November: 1.51 s of main thread, 39.3 MB of JSON, of which the record 7.9 MB and the pawns’ copied events 5.3 MB. VB-226 cuts what is left after this task and VB-204.ready.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).
npm test passes (86 scripts). npm run verify passes but for tests/history.js, which fails identically at 7812253 (routeExpand,
routeRefresh, walkTies, roundPairs, heirRank and roundRank over their limits on the stale fixtures; recordFold 0 in its window).cenv and pawns, the 12
year entries record, and all 16 gain recordYears and recordFold; nothing else changed. Counters: recordFold added at 0.tests/record.js: every kind written (literal kinds of personEvent, log and record) and every kind on the record is in HISTORY;
heirs 7 at 2.5 years, the times and texts of all 230 pawn events hash as the copies did at 7812253; founders 7 after 10 years and 12
days: routine events older than their years are folded, each count has as many slots as its tally, one count per kind, village and
year, and a folded position reads its count; a save in the middle of a fold ends it as the run does; and small-y5, saved with
copies, loads with 10,416 pawn events reading as they did (72 routine copies dropped).| 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.
foldHistory called a day at a time on the loaded saves): the first fold of an old save is the largest, small-y40
26 days (25 villages and none), at most 13.0 ms a day (127 ms in all, 3.5 M slots passed), medium-ref 27 days, at most 11.1 ms; a
year’s fold after that, at most 0.4 ms (small-y40) and 0.8 ms (medium-ref) a day, 3 to 7 ms a year. The simulation runs as before,
so no household is better or worse off.