diff --git a/internal/gui/sessions.go b/internal/gui/sessions.go index fa5db8ce2..add8cbe66 100644 --- a/internal/gui/sessions.go +++ b/internal/gui/sessions.go @@ -509,7 +509,7 @@ func warmSteps() []func() { func() { underTightGC(func() { usage.QueryPage(usage.All, usage.Filter{}, 0, 50) }) }, func() { if slices.ContainsFunc(statsFor(0).Keys, func(k string) bool { return strings.HasPrefix(k, "codex:") }) { - warmCodexEffort() + underTightGC(warmCodexEffort) } }, } @@ -536,8 +536,10 @@ func warmUp(steps ...func()) { // what was set; a GOGC the user set lower, or off, is kept. The usage // page's read of the whole history holds every row of it at once (~270 MB // live for 390k calls), and a cold start that rests at ~200 MB peaked at -// 555–587 MB in Activity Monitor there; under it, 410–438 MB. Only that -// read runs under it: the warm-up as a whole did too for ~11 s more CPU. +// 555–587 MB in Activity Monitor there; under it, 410–438 MB. That read +// and Codex's effort, which reads the whole ledger again while the page +// still holds its rows, run under it: the warm-up as a whole did too for +// ~11 s more CPU. func underTightGC(fn func()) { if was := debug.SetGCPercent(tightGCPercent); was < tightGCPercent { debug.SetGCPercent(was) diff --git a/internal/gui/sessions_warm_test.go b/internal/gui/sessions_warm_test.go index ebf3464ba..91fa74742 100644 --- a/internal/gui/sessions_warm_test.go +++ b/internal/gui/sessions_warm_test.go @@ -2,6 +2,7 @@ package gui import ( "runtime" + "runtime/debug" "testing" "time" @@ -33,7 +34,9 @@ func TestWarmUpReturnsItsGarbage(t *testing.T) { // With Codex sessions on this computer the warm-up also reads Codex's // per-thread effort, which a first Codex page after a start otherwise read // from the whole ledger while it waited (#2776); without any it doesn't. +// It reads under the tight GC: the usage page's rows are still held then. func TestWarmUpReadsCodexEffort(t *testing.T) { + defer debug.SetGCPercent(debug.SetGCPercent(100)) statsMemo.Lock() saved := statsMemo.m statsMemo.Unlock() @@ -55,7 +58,12 @@ func TestWarmUpReadsCodexEffort(t *testing.T) { } statsMemo.Unlock() read := 0 - warmCodexEffort = func() { read++ } + warmCodexEffort = func() { + read++ + if p := gcPercent(); p != tightGCPercent { + t.Errorf("Codex's effort was read under GOGC=%d, want %d", p, tightGCPercent) + } + } warmUp(warmSteps()...) if read != c.want { t.Fatalf("with sessions %v Codex's effort was read %d times, want %d", c.keys, read, c.want)