From 936bdccfabb36f5fd5d672631236ab619826f3ca Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 07:51:47 +0800 Subject: [PATCH] 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). --- internal/gui/page_memory.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/gui/page_memory.go b/internal/gui/page_memory.go index 2de27075b..99a30cac7 100644 --- a/internal/gui/page_memory.go +++ b/internal/gui/page_memory.go @@ -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