Commit Graph
2 Commits
Author SHA1 Message Date
yetone fddd7ff08f usage: pairing keeps its rows as bits and its groups by sums, and lets its pairs go (#2278)
A cold start pairs the whole history, and pairing held its row sets as
map[rowRef]bool, ~40 bytes a row, several sets of most rows at once.
They are now refSet: a bitset a chunk, a bit a row. matchScratch's
groupOf was keyed by the whole matchKey (a session string and its
tokens); it is keyed by a 128-bit maphash sum of them now, and the
sessions map is filled when a group is made. pairedRows' pairs and
compactions maps were filled and never read; they are gone.

Measured on mote, a copy of the real full history (52G Codex, 13G
Claude), GODEBUG=gctrace=1, 120s of /api polls, 3 rounds each,
alternating, v0.1.2143 (807048470) against this change:
  peak live heap  459 -> 439 MB (512/426/440 vs 470/433/413)
  heap at GC      543 -> 517 MB
  footprint peak  677 -> 641 MB
The inuse profile at the peak shows groupOf 28.7 -> 11.8 MB and the
matched set gone from matchedBlocks. This is a small part of the peak;
the rest is the full re-pair itself, which is next.

Run at this tree (rebased onto dca3e2d71 from 807048470), on mote:
go vet ./internal/usage; GOOS=linux|windows|darwin go vet -tags nogui
./... all ok; go test -count=1 ./internal/usage ok (30.1s), with the
new TestRefSet and TestMatchKeySum (no allocation).
Not run: the full suite, the GUI suite.
2026-10-30 13:42:11 +08:00
yetone c272f3799e usage: a session file's Codex ids are hashed once while it stands
A Usage page polled while one session was live paired every chunk of the
period again, and foldCodexRows decoded each session file to hash the
same response ids: ~40 MB a poll of today's page, more than any other
part of it. Each chunk's Codex log calls are now kept by its serial as
one uint64 each (the id's hash shifted over its index, 8 bytes a call),
for the four folds after the last that read them, so a poll decodes
only the chunks that changed. Calls whose hash is the same are still
told apart by their ids after, as before.

Run (worktree clip; tests and vet again at this head, rebased on b7d5a97fe):
- go test -count=1 ./internal/usage/ ./internal/usageapi/: ok
- TestFoldReadsAChunksIDsOnce: red with the cache turned off by hand
  (the second fold read both chunks again), green with it
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/usage/: clean
- A/B, ab5.sh (warm start in a sandbox HOME with a copy of the real
  history, then 8 GUI-like polls 15 s apart), v0.1.1659 vs this:
  allocated over the polls 2.99 GB -> 2.39 GB; queryPage 726 -> 442 MB;
  foldCodexRows 326 MB -> under the profile's floor;
  /api/usage/requests?period=today mean 154 -> 100 ms;
  /api/sessions 305 -> 213 ms; footprint 10 s into each rest
  164-193 -> 156-187 MB.

Not done here: codexChunkResponsePairs, visibleLocal and Codex effort's
visit still decode every chunk a poll (~117, 85 and 91 MB over the run).
2026-10-27 08:46:33 +08:00