TestPairScratchKeepsNothingBetweenCalls was red after any test that
paired another pairFixture of other sizes first: both fixtures named
their chunks 100, 101, ..., so msgKeysOf, which keeps a chunk's message
keys by its serial, read the other fixture's ids for this one's chunks
and left 18 of 108 calls out as copies ("a first call matched 90 of
108"). It passed alone and in the package's full order, so it showed
only under a -run of the pairing tests.
Run at the rebased tree (on origin/main 387e8572a, on mote): gofmt -l clean;
go vet -tags nogui ./internal/usage/ for linux, windows and darwin ok;
go test ./internal/usage/ ok (34.5s), ./internal/usageapi/ ok;
-run 'VisibleLocal|Pair|PageSplit|Heat|Effort|QueryPage' ok.
Broken by hand (serials 1 and 100+f again): that -run is red,
TestPairScratchKeepsNothingBetweenCalls "a first call matched 90 of 108".
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.
Under polls, with calls coming in, GC was ~35% of magpie's CPU and
madvise another 16%, both driven by how much a poll allocates. The
pairing that the heatmap and every page run did most of it: in an 80 s
heap diff on a year's history, matchedBlocks allocated 3.2 GB and
codexChunkResponsePairs 2.6 GB.
- matchedBlocks: a match key holds a call or two, so each key's ends
and range counts were two slices of their own. They are now one ends
slab and one counts slab, a group an offset into them, and groupOf is
made the size of the calls it keeps. The candidates and unique maps
are a slice and a []bool over slab positions.
- codexChunkResponsePairs: picks and their slab are made the size of
the gateway's response ids, and a gateway call is judged from its
packed strings (codexGatewayCall) instead of being made a whole Row.
What a call pairs with is unchanged.
BenchmarkPairRows (new; 2,000 session files of 100 calls, half Codex by
response id, half Claude Code by session and tokens), on mote:
e0ea15b8e: 170,154,300 B/op, 208,673 allocs/op
this: 100,846,208 B/op, 7,056 allocs/op
(ns/op isn't comparable: mote was at load 20-35, both ~0.7-1.0 s/op.)
Not yet measured: the poll-and-feed A/B against a real build on mote
(load 86 from other runs); its numbers go on #2278.
Run at this head on mote: go test ./internal/usage ./internal/usageapi
ok; go test ./internal/sessions ok; ./internal/gui: TestMainWindowCorners/
macOS_26_SDK red only, #3949 (macOS 27 AppKit, untouched here); go vet
-tags nogui ./internal/usage/... ./internal/gui/... ./internal/usageapi/...
for linux, windows and darwin ok.
Broken by hand: the counts slab without the group's +k offset (groups'
range counts overlap) failed TestIndexedExportMatchesExhaustiveOracle,
TestRequestMatchIndexEquivalent, TestMatchOpensOnlyNamedChunks and
TestCodexCacheWriteMatchesGatewayCall; codexGatewayCall taking a
rejected call failed TestCodexRejectedGatewayDoesNotPairWithNativeCall.
Not run: the full ./... suite.