Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
sessions: a page-asked first read uses half the cores, not twice them (#3238)
yetonef8fa8147badf
diff --git a/internal/sessions/quiet.go b/internal/sessions/quiet.goindex dd40f7e34..c7402c0cf 100644--- a/internal/sessions/quiet.go+++ b/internal/sessions/quiet.go@@ -24,6 +24,14 @@ var (// quietReaders is how many files the warm-up reads at once.func quietReaders() int { return max(1, runtime.NumCPU()/4) }+// scanReaders is how many files the index reads at once with a page+// waiting. It was twice the cores, up to 32, as if the reading waited on+// the disk; it doesn't on an SSD, decoding and parsing is the work, and a+// first read of 15 GB of Codex sessions held 22 of 32 cores (2154%) while+// the page waited, the machine's other apps slowed beside it (#3238). Half+// the cores leaves the other half to them.+func scanReaders() int { return max(2, runtime.NumCPU()/2) }+// Warm runs fn, the reads nobody waits on yet, with few readers.func Warm(fn func()) {warming.Add(1)diff --git a/internal/sessions/quiet_test.go b/internal/sessions/quiet_test.goindex 3a6a9b392..48f6a45a0 100644--- a/internal/sessions/quiet_test.go+++ b/internal/sessions/quiet_test.go@@ -124,3 +124,19 @@ func TestLongReadKeepsWhatItRead(t *testing.T) {t.Fatal("nothing kept on disk until every file was read")}}++// With a page waiting, the index reads with half the cores, not twice+// them: a first read held 22 of 32 cores beside the user's apps (#3238).+func TestAskedIndexReadsWithHalfTheCores(t *testing.T) {+ inZone(t, 0)+ claude, _ := setup(t)+ moreSessions(t, claude, 4*scanReaders()+8)+ parseHook = func() { time.Sleep(20 * time.Millisecond) }+ t.Cleanup(func() { parseHook = nil })+ readPeak.Store(0)+ defer Ask()()+ statsAt(0, statsNow)+ if n := readPeak.Load(); n > int32(scanReaders()) || n < int32(min(2, scanReaders())) {+ t.Fatalf("the index read %d files at once, want 2 to %d", n, scanReaders())+ }+}diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.goindex f7ab8f742..e5542b0ba 100644--- a/internal/sessions/sessions.go+++ b/internal/sessions/sessions.go@@ -865,7 +865,7 @@ func refresh(want, all []file) {// the whole scan finishes.windows := summaryRevisionWindows(todo, time.Now())// the biggest first, so no long file is left to run on alone at the- // end; and twice the cores, as the reading waits on the disk+ // end; with half the cores (scanReaders)sort.Slice(todo, func(i, j int) bool { return todo[i].size-offOf(todo[i]) > todo[j].size-offOf(todo[j]) })left := make(map[string]int64, len(todo))var total int64@@ -887,7 +887,7 @@ func refresh(want, all []file) {mu.Unlock()ch := make(chan int)finished := make(chan int, len(jobs))- for i := 0; i < min(max(8, 2*runtime.NumCPU()), 32, len(todo)); i++ {+ for i := 0; i < min(scanReaders(), len(todo)); i++ {go func() {for i := range ch {j := &jobs[i]