gui: a page's read and the warm-up collect at GOGC 10, not 25 (#2278)

tightGCPercent goes from 25 to 10. This is the GOGC that underTightGC (the
warm-up's reads) and every /api/sessions* and /api/usage* answer
(held) run under; it is put back once the last read ends.

Profiled on mote (heap dumps at each 8 MB of live heap, plus a goroutine
dump). After v0.1.2280 the first start's reads already take turns, so the
peak is one build at a time over what the indexes keep. The live peak is
~280 MB, and at GOGC 25 Go let the heap grow ~70 MB past that before a
collection.

Bench: the mote sandbox HOME with the real history (13k sessions, ~720k
gateway calls), MAGPIE_NO_STATS=1, a poll of ten answers every 5 s,
75 s per run, footprint peak (phys_footprint_peak):
- cold start (no caches), 3 runs each:
  - v0.1.2280: 397/390/392 MB, 162–168 s user CPU, slowest first answer
    29.8–30.6 s
  - this change: 352/350/352 MB, 197–200 s user CPU, slowest first answer
    31.9–32.4 s
- start with caches, 2 runs each:
  - v0.1.2280: 321/304 MB, 7.6 s user CPU
  - this change: 271/275 MB, 10.3 s user CPU, mean answer 0.12 → 0.13 s

Tried and dropped:
- 10 only until the warm-up ends: cold 372–374 MB, warm 301–306 MB.
- 10 only inside usage's big builds (a holdBigBuild hook): cold
  373–395 MB, warm 304–312 MB. The peaks are not all big builds.
- Warming the heatmap as a fifth warm-up step: cold 395–401 MB, the same.
  The goroutine dump shows the page asks already take their turns.

Run on mote, first at 7f2acb9ff + this, then again after the rebase onto
a6951cc63 (which brought a GLM card fix, the WorkBuddy min and the main
window's footer):
- go vet ./...: ok, at both heads.
- go test -timeout 45m ./internal/gui/ at 7f2acb9ff + this: every test
  passed except TestCoveredWindowStaysUp (#4125).
- The same run at the rebased head: ten real-window AppKit tests were
  killed at their deadlines (dock, panel, tray, titlebar, plugin page,
  covered window). Five of them, run alone on a clean a6951cc63 checkout
  without this change, were killed the same way while another session's
  GUI suite loaded mote. They are filed: #4125, #2645, #1936 and #3178.
- gofmt -l: clean.
Not run: the Linux vet of internal/gui (Wails needs cgo to cross-compile,
and the WSL distro has no gtk4). The change is a constant and comments.
This commit is contained in:
yetone
2026-10-31 07:42:25 +08:00
parent a6951cc63a
commit 03d21ab8e1
2 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -2629,7 +2629,7 @@ func held(h http.Handler) http.Handler {
defer sessions.Ask()()
// and what the read threw away goes back once the page rests
defer readingPage()()
// and collected under GOGC 25 while it runs: a poll's reads
// and collected under GOGC 10 while it runs: a poll's reads
// allocated ~330 MB to keep ~105 MB, and at the default 100 the
// heap grew to twice what it kept before a collection, ~320 MB
// in Activity Monitor during a poll. No memory limit: held as
+10 -4
View File
@@ -753,12 +753,12 @@ func coldTurn(h http.HandlerFunc) http.HandlerFunc {
}
}
// underTightGC runs fn letting the heap grow by a quarter of what it holds
// underTightGC runs fn letting the heap grow by a tenth of what it holds
// before a collection, not Go's default of all of it, and then puts back
// 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. That read
// 555–587 MB in Activity Monitor there; under a quarter, 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.
@@ -776,7 +776,7 @@ func underTightGC(fn func()) {
// tightGC is what the reads under a tight GC hold: the first to begin sets
// it, and the last to end puts back what was set before it. Each read
// putting back what it found let two at once leave GOGC at 25 for good,
// putting back what it found let two at once leave GOGC tight for good,
// when the first to begin ended before the second.
var tightGC struct {
sync.Mutex
@@ -805,7 +805,13 @@ func tightenGC() (undo func()) {
})
}
const tightGCPercent = 25
// tightGCPercent is a tenth. Under a quarter, a first start's footprint
// peaked at 390–397 MB, and a start with its caches at 304–321 MB, on a
// live heap of ~280 MB and ~250 MB: each read, and the window's polls
// beside it, let the heap grow by ~70 MB first. Under a tenth, 350–352
// MB and 271–275 MB, for ~20% more CPU in the first start's minute and
// ~2 s a minute of polls asking ten answers every 5 s (#2278).
const tightGCPercent = 10
// agentCommand is the shell line that starts a: its Launch where it has
// one (agy, Claude Science, Cursor Private Inference), else its own