Commit Graph
2 Commits
Author SHA1 Message Date
yetone 157d575c39 usage: pairing Codex calls by response id allocates no pick an id (#2278)
codexChunkResponsePairs kept a *pick for every response id the gateway
had. The alloc profile of v0.1.1928 on mote (34k session files, 240k
gateway rows, two minutes of polls while an agent worked) had it at
1.05 GB, &pick{} alone 308 MB. The picks are now one slice the map
holds places in, so a poll makes a few slice growths, not an allocation
an id. What is paired is unchanged: every pick is still read once.

TestPairsAllocateNoPickAnID: 4000 Codex calls named once on both sides
are all paired, and a second pairing makes at most n/4 allocations. Red
on the old code (4161 allocations), green on the new.

Run on mote at the pushed head (origin/main 655f8dbd1 plus this; rebased
onto b7da6cf93, a gateway test commit that touches neither package):
  go test -count=1 -timeout 45m ./internal/usage/ ./internal/sessions/
    ok (30.8s, 37.9s)
  GOOS=linux/windows/darwin go vet -tags nogui ./internal/usage/ ok
Not run: the GUI suite (no GUI file changed; at 655f8dbd1 it was red
only in TestMainWindowCorners, #3949), an A/B of the page (next).
2026-10-29 00:57:04 +08:00
yetone 51af40f9cb usage: a poll pairs Codex calls by id without decoding the session files the gateway names none of
codexChunkResponsePairs decoded every local chunk of the period on each
Requests poll to look up the few response ids the gateway logged. The ids
kept per chunk serial for the fold (foldIDs) now hold every call's id hash,
not only Codex log calls', and a chunk none of whose hashes is a pick's is
skipped. The pick is still made by the id string, so a hash match only
reads a chunk, never pairs one.

Measured on real history (rss-home, 8 GUI polls 15s apart, after a 90s
warm start), magpie-ids vs v0.1.1677's code, two runs each:
- CPU profile: pairRows 0.74s/0.70s vs 0.85s/0.89s; chunk unpacking
  0.65s/0.59s vs 0.74s/0.81s; codexChunkResponsePairs 0.13-0.18s gone.
- Allocations: the 191MB the pairs decoded is gone from it, but most of
  it moves to visibleLocal, which now grows the pooled row buffer the
  pairs grew before. Total 2671MB vs 2528MB, within live-history noise.

Run at the pushed head (on 2afacd7d1):
- go test ./internal/usage/... ./internal/usageapi/...: ok
- go test ./internal/gui/: ok on the base before the rebase (50606d8c0);
  the two commits rebased over touch neither usage nor its callers
- GOOS=linux/windows/darwin go vet -tags nogui ./internal/usage/ ./internal/gui/: ok; gofmt clean
- TestPairsReadOnlyChunksTheGatewayNamed: red with the skip taken out
  (read 2 local chunks), green restored.

Not tried: the live app; the A/B ran on rss-home, which reads the real
history read-only.
2026-10-27 12:16:01 +08:00