Each Sessions poll lists every Codex rollout (~13k here) and made two maps over them anew: distinctCodexFiles' first file of each name, and codexFilesIn's set of plain rollouts a compressed twin defers to. Both are now taken from a shelf, as pathSets are, and given back cleared; the shelf lets them go after it idles. Run on mote (M5 Pro, macOS 27), with a copy of the real accounts: - go vet ./internal/sessions; go test ./internal/sessions: ok. - TestDistinctCodexFilesKeepsItsSet (new): a call over 4,000 rollouts makes at most 4 allocations. Broken by hand (a new map each call): 47, red. The twin set has no test of its own; it uses pathSet as is. - /api/sessions and /api/sessions/stats?days=30 from a fresh start, real history: byte-identical to v0.1.3503's code. - 40 /api/sessions polls with X-Magpie-Had: 185.5 MB allocated before, 152.4 MB with this; distinctCodexFiles is gone from the profile.
27 lines
763 B
Go
27 lines
763 B
Go
package sessions
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
// distinctCodexFiles runs on every Sessions poll over every rollout; its
|
|
// set of names is kept from call to call, not made again for each (#2278).
|
|
func TestDistinctCodexFilesKeepsItsSet(t *testing.T) {
|
|
files := make([]file, 4000)
|
|
for i := range files {
|
|
files[i] = file{agent: "codex", path: fmt.Sprintf("/c/sessions/2026/11/10/rollout-%05d.jsonl", i)}
|
|
}
|
|
work := make([]file, len(files))
|
|
run := func() {
|
|
copy(work, files)
|
|
if got := distinctCodexFiles(work); len(got) != len(files) {
|
|
t.Fatalf("kept %d of %d distinct rollouts", len(got), len(files))
|
|
}
|
|
}
|
|
run()
|
|
if n := testing.AllocsPerRun(10, run); n > 4 {
|
|
t.Errorf("a call over %d rollouts: %.0f allocations, want a few", len(files), n)
|
|
}
|
|
}
|