scanAt gave every scan a 1 MiB bufio buffer. A start reads ~4,600
mostly small session files (and reads each again from where it was
left), so those buffers were the largest single allocation of a start:
9.4 GB of the 22.4 GB a warm start allocated on the sandbox below. The
buffer is now the rest of a plain file plus one byte, at least 16 KiB
and at most 1 MiB; a packed (zstd) file keeps 1 MiB. A line longer than
the buffer (a file grown since its size was read) is still read whole
through scanAt's long-line path.
Tests (internal/sessions/scan_buffer_test.go):
- TestScanOfASmallFileTakesASmallBuffer: 200 scans of a two-line file
allocate under 64 KiB each. With the 1 MiB buffer back: red, "a scan
of a two-line file allocated 1048871 bytes".
- TestScanReadsALineLongerThanItsBuffer: a line three buffers long, then
a short one, are both handed over whole.
Measured on a sandbox instance (600k gateway calls, ~4,600 sessions),
base 1a3b92688 against this branch with every #2776 commit, back to back
at a load average of 340-450 (nine agents running suites), heap profile
after the four first API calls and 60s idle:
allocated of it scan buffers live heap
warm base 22.40 GB 9.40 GB 483 MB
warm new 15.86 GB 1.98 GB 498 MB
cold base 22.48 GB 9.31 GB 450 MB
cold new 15.76 GB 1.98 GB 498 MB
What is left in bufio.NewReaderSize is the other call readers' own
1 MiB buffers (calls_pi, calls_kimi, ...). Peak RSS did not drop at this
load (base 4.38/4.41 GB, new 4.59/4.54 GB): the peak comes from the four
first calls each materialising the 600k-call ledger at once
(gatewayRecords appends every Record, 2.56 GB allocated; ledgerOfAt
6.2 GB for CodexModelEffort), which this commit does not change.
Run on origin/main 2ceff7370 with all four #2776 commits' changes
(this one and the three beside it), load average 291-568 (nine agents
running suites), macOS:
- go test -p 4 ./... -timeout 45m, 09:35-10:49: 62 packages ok,
among them agent (2310s), gateway (1707s), provider (764s), usage
(83s). Red:
- internal/sessions: TestWSLOmpProfiles, TestWSLStoppedDistroKept,
TestWSLStoppedSinceNotOpened, TestWSLNoneWithoutHomes, each
"TempDir: mkdir ...: no space left on device" (the disk filled
mid-run). After space was freed, ./internal/sessions alone: ok
(139s).
- internal/gui: TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt,
TestPanelJoinsFullScreenSpaces, TestPluginPageLoadsItsFilesInTheWindow,
TestDockReopenKeepsTheWindowsSpace (each killed at 30s) and
TestMainWindowCorners (86s): the real-window AppKit tests under
load, already filed as #2645 and #1936. Rerun alone at load ~335:
all pass, with TestSetAnswersWhileDevinAndProvidersHang (17s).
- gofmt -l: none. go vet: darwin, GOOS=linux -tags nogui and
GOOS=windows all exit 0.
- No internal/gui/assets file changed, so the GUI Playwright suite was
not run.