gui: the page reads hand memory back only after 30s at rest, past every poll (#2278)

An open Usage or Sessions window polls every 10s and 15s. With a 3s rest,
every poll's pages were handed back (ReleaseScratch + FreeOSMemory) and
taken back by the next poll: in the CPU profile, 1.88s of 1.95s madvise
was runtime.sysUsed re-committing them, and the matcher's scratch was
made again on every poll. 30s outlasts both polls, so the pages go back
once a window stops polling, not between an open window's polls.

Measured on mote (~/r2278 run2278d: 10 endpoints every 5s, gateway feed
from 60s, real ~/.codex and ~/.claude copy), 60s CPU profile, 3s vs 30s:
  GC mark workers  6.92s -> 4.76s
  madvise          1.81s -> 1.18s
  avg RSS after 60s  893 -> 925 MiB (+32 MiB while polling)
Latency was not comparable (mote load 40-73 during the run).
The binary measured was this constant at f193c3865. Rebased onto
91a2f603c (a masking commit and a .cjs GUI test only), and the vet and
test below were run again after it.

Run at the pushed head on mote: GOOS=linux/windows/darwin go vet -tags
nogui ./internal/gui/ ok. go test ./internal/gui/ red only in
TestMainWindowCorners/macOS_26_SDK, the open #3949.
Not tried: an open window left polling for an hour (RSS stays at the
poll's working set by design).
This commit is contained in:
yetone
2026-10-29 07:58:26 +08:00
parent 91a2f603cd
commit 936bdccfab
+6 -3
View File
@@ -17,9 +17,12 @@ import (
// reads aren't its requests. So once those reads have rested for
// pageRest, what they left goes back at once, as the warm-up's does.
// pageRest is how long the page reads rest before that: a poll's few
// reads come within a second of one another.
const pageRest = 3 * time.Second
// pageRest is how long the page reads rest before that. It outlasts the
// pages' polls (Usage every 10 s, Sessions every 15 s), so the pages go
// back once a window stops polling, not between an open window's polls:
// at 3 s every poll took back the pages the last one handed back, and
// madvise and the collections it drove were ~40% of the CPU (#2278).
const pageRest = 30 * time.Second
var pageReads struct {
sync.Mutex