Commit Graph
1 Commits
Author SHA1 Message Date
yetone c2c08850f6 usage: a request state hashes Codex's thread identities without encoding them
readRequestState json.Marshal()ed every Codex thread's identity (~20k
over a real history) into a new buffer only to write it into the key's
hash, on every requests page and effort ask: every 15 s poll. They are
now written into the hash directly, each field length-prefixed, in the
order of their keys. The key lives in memory only (the disk index is
keyed by meta), so the changed form costs nothing on upgrade.

Benchmark, 20k identities (a throwaway benchmark, not committed):
json.Marshal + hash 7.06 ms, 6.49 MB, 40012 allocs an ask; now 3.36 ms,
0.36 MB, 3 allocs. In a 12-poll real-history run json.Marshal under
readRequestState was 116 MB.

Test: TestCodexIdentitiesHashed (same identities in another order hash
the same; a thread turning subagent changes it; ab|c is not a|bc; none
is not one). It fails with the length prefixes taken out by hand. The
rest of the package's tests passed with this hash removed altogether:
an identity changes only with a rollout, whose size and time are in the
key too.

Run at this tree: go test ./internal/usage/ ok (8 runs; one earlier run
of this change printed a bare FAIL whose test I lost to a tail, not
seen again in 8 package runs and 30 of the effort tests); gofmt -l
clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/usage ok.
2026-10-27 08:04:30 +08:00