Pre-bake the landmark statutes: 14.2s of compute becomes a file read

↗ view on GitHub · Eli Ziff · 2026-07-31 · d8d88215

Eli: "we should definitely do some pre-caching of the ITA and the criminal
code; those are important documents and they are worth pre-baking for their
graphs etc because that's heavy computation but exactly where I think having
a pre-made cache will pay off."

He is right, and the in-memory memo does not touch this case. It fixes
repetition WITHIN a process; a landmark statute compiled cold on a laptop pays
in full at every restart. These are also precisely the documents a model must
navigate rather than read, because reading them is not an option.

Measured, baking eight federal acts:

  Income Tax Act        7,318,921 chars  30,812 nodes  20,763 edges
                        skeleton 676ms   graph 12,328ms
  Criminal Code         2,262,608 chars  10,979 nodes   5,737 edges
                        skeleton 218ms   graph 518ms
  + CBCA, BIA, PIPEDA, Copyright, Trademarks, Competition
  14.2s of compute, 27 MB on disk

Served: Income Tax Act cold compile 13,444ms -> baked read 658ms (20x);
Criminal Code 793ms -> 197ms (4x).

CORRECTNESS, checked rather than assumed: node inventory, edge list and graph
counts are all digest-identical between a baked read and a cold compile, and
the rehydrated SourceDoc's index is rebuilt at full size (61,624 entries for
the ITA). That last one is the trap -- `SourceDoc.index` is a Map, so a naive
JSON round trip yields `{}` and every lookup silently answers "not found".
The sidecar therefore stores the JSON-safe inventory and rebuilds the doc
through `createSourceDoc`, which is O(blocks) and does not tokenize. `tokens`
is a non-enumerable lazy accessor that structuredClone drops and cannot
re-attach, so persisting a SourceDoc in any form is off the table.

Content-addressed on the text, so a consolidation update simply misses and
re-bakes -- no staleness to manage, no invalidation to get wrong. Versioned
so a compiler change can never be served from a stale bake. A read that fails
for any reason falls through to a real compile: correctness never depends on
a hit, only speed does.

Nothing is wired to consume the sidecars yet -- that is a deliberate next
step, not an oversight, since the read path should be measured before the
product depends on it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H9ToHYJVDxfeJcJwdzrP2H
Repository eliziff/Beaver
Author Eli Ziff <eliasziff@gmail.com>
Authored
Parents f15c3895
Stats 3 files changed , +318
Part of SourceDoc / DOCX engine: redlines, tracked changes, editing benchmark

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-d8d88215.md from inside the repo you want the change in.

⬇ Download capture-commit-d8d88215.md