Skip to content

perf: store the session cache in day pieces - #1550

Merged
iamtoruk merged 7 commits into
mainfrom
perf/bounded-load-stage2
Sep 24, 2026
Merged

iamtoruk merged 7 commits into
mainfrom
perf/bounded-load-stage2

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Second stage of bounded cache loading, on top of #1542.

What changes

  • Day pieces (session cache layout v10). The session cache is stored as pieces bucketed by the UTC day of each file's newest call, plus a small per-provider index (one row per cached file: piece, fingerprint, first and last call time, flags) and a key file per piece holding its dedup keys. today streams only today's pieces; a save rewrites only the pieces it touched. Pieces are plain stage-1 line-format shards, so the line reader, memo and full loads are reused.
  • Old Claude transcripts stop re-parsing on every narrow query. Main re-parses any Claude transcript outside the query's month scope on every overview -p today and every menubar refresh (a June file re-parses on each poll). The index knows every cached file's fingerprint, so unchanged ones are skipped.
  • Dedup still sees every key. Before any whole-file Claude parse, the dedup set is seeded from the key files of unchanged transcripts outside the query's months. Without this, a fork or resume of a transcript older than the month scope (which replays its message ids with new timestamps) would be counted twice. This also removes a double count main has today when the fork is discovered before its original.
  • Streaming migration from v9. Lossless, one member at a time, works on single-line shards from older builds; v9 is removed only after v10 has published. A downgrade is a cold re-parse, like every layout bump.
  • Key files are written without fsync; a missing or corrupt one is rebuilt from its piece.

Verification

Figures against main, frozen pricing, fresh and upgrade (v9 -> v10): 66/66 commands identical on a real corpus (2.1 GB Claude, 4 GB Codex), 66/66 on a synthetic heavy corpus, 78/78 and 98/98 on two edge corpora (sessions across midnight and months, moved/shrunk/deleted files, forks and resumed copies of out-of-scope transcripts in both discovery orders, spawn anchors, WSL-offline members, June files), under local, Pacific/Kiritimati and America/Adak time zones. Member diff and load order equal main after every command. Longer ranges never total less than shorter ones inside them.

Robustness: SIGKILL at 7 points during migration then rerun, outputs equal main; truncated, empty, garbage and deleted key files, outputs unchanged; 12 concurrent processes plus a serve child with random SIGKILLs during saves, no crash, no unreadable file, outputs equal main.

Speed and memory, warm, median of 5:

main #1542 this PR
heavy, overview -p today 4.66 s, 3,501 MB 3.62 s, 669 MB 1.00 s, 557 MB
heavy, menubar payload 4.75 s, 3,457 MB 3.63 s, 701 MB 1.05 s, 564 MB
real, overview -p today 0.83 s, 966 MB 0.64 s, 270 MB 0.48 s, 239 MB
real, menubar payload 0.95 s, 973 MB 0.76 s, 280 MB 0.60 s, 253 MB

The heavy corpus passes overview -p today and the menubar payload at a 384 MB heap cap (main fails at 1 GB). The first run after upgrading streams the migration: peak heap 784 MB instead of #1542's 2.7 GB, about 10 s once. A save that rewrites every piece (every fingerprint changed at once, e.g. a restored home folder) takes ~520 ms instead of ~230 ms.

tsc clean; full suite green except RootDeepProjectLabels.test.tsx, which fails identically on main in this checkout; test:locks 36/36. Six new tests fail on #1542's source: piece selection, lost key file, cross-day move, lossless migration, migration write failure, old-file reconcile, plus the out-of-scope fork dedup test.

Not covered

The Codex results file is still parsed and rewritten whole when a rollout changes (on the real corpus a warm today poll goes from 0.5 s / 240 MB to 0.9 s / 870 MB after one append). That cache has its own version and migration and is the next stage. Windows and live WSL roots were not run.

Layout v10: a provider's files live in pieces by the UTC day of their
newest call, each with a key file, and an index row per file (piece,
fingerprint, call span, v9 month) read on every load. A ranged load reads
the index, the key files and only the members it reports on; a save
rewrites only the pieces it touched. Rows keep v9's full-load order and
month scope, so orphans, the first-paint snapshot and dedup see what they
saw on v9. The v9 month shards re-lay out once, streaming, and are removed
after v10 publishes.
v9 could not see them, so every narrow query re-parsed each older Claude
transcript it discovered and republished the cache. The index knows their
fingerprint; an unchanged one needs nothing, a changed one still re-parses
as if uncached.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli The codeburn CLI and its core parsing/reporting engine enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants