ac4af582301a4e8a29245dbba767eba31334ddf9
6
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c76bcaea7a |
gui: between reads the heap grows by half of what it holds, not all of it
The window and the app's page, resting on ~60 MB live, poll /api/state,
/api/drift and /api/providers and throw ~10 MB away a round. At Go's
default GOGC of 100 the heap grew to twice what it kept before each
collection, so the footprint stood at 121-135 MB and peaked at 136-138
MB for a ~60 MB heap.
steadyGCStart, run once with the warm-up, sets GOGC to half, or to what
lets the heap grow by 32 MB when that is more (never above 100), and
sets it again for the live heap after each collection, through the
retightenGC hook the tight reads already use. The usage and sessions
reads under a tight GC still set their tenth while they run, and the
steady value comes back after them. A GOGC the user set in the
environment is kept, and nothing is retuned. No memory limit (#2278).
Run (mote, at this tree):
- go test -count=1 ./internal/gui: ok except TestSettingsSaveKeepsWhatItDoesNotSend
(#4514) and TestMainWindowCorners (#3949), the known reds.
- -run 'GC|Steady|Tight' 3 times and once under -race: ok.
- Broken by hand: ignoring GOGC in the environment, TestSteadyGCKeepsTheUsersGOGC
is red ("GOGC=200 set by the user, magpie runs under 50"); with no
retune after a collection, TestSteadyGCRetunesAfterACollection is red
("GOGC after collections = 50, want 100").
- gofmt -l, go vet, GOOS=windows go vet -tags nogui ./internal/gui: clean.
- Real accounts, magpie web in a sandbox HOME, 40 rounds of the three
polls, twice each, alternating, v0.1.2507 against this change:
phys_footprint_peak 136 / 137 MB -> 115 / 116 MB
phys_footprint end 135 / 121 MB -> 96 / 94 MB
CPU of the polls 3.84 / 3.98s -> 4.05 / 4.24s
/api/state and /api/drift byte-identical.
GOGC=50 in the environment gave 107-108 MB at +9% CPU; the 32 MB room
keeps a small heap from collecting that often.
Not run: the desktop window (Wails) and Windows/Linux machines; the
tray app takes the same Handler path. A large usage history between
reads (~280 MB live) now grows by ~140 MB, not ~280, before a
collection; not measured here.
Picked onto
|
||
|
|
0bf5adb118 |
gui: a tight GC lets a small heap grow by 32 MB, not a tenth (#2278)
The usage and sessions reads run under GOGC=10. On a first start they begin on a ~50 MB live heap and allocate ~400 MB a second, so a tenth was a collection every few MB: 2,102 to 2,239 collections in the first 75 s, about 70 s of the start's CPU, and each one emptied the zstd and bufio pools, which were then allocated again. While a read is under a tight GC, each collection now sets GOGC for the heap it left: tightPercent gives a tenth, or enough for 32 MB of growth, never above what was set before (a lower or off GOGC is kept). A heap over 320 MB is held to a tenth as before. The hook is a finalizer re-armed after each collection while a read is under it. Cold start on mote's copy of the real history (75 s, two runs each, v0.1.2330's lastIndex build vs this): - CPU 3:46.66 / 4:00.50 -> 3:08.69 / 3:10.04 (user 3:18.97 / 3:28.67 -> 2:44.23 / 2:45.85) - collections 2,239 / 2,102 -> 706 / 705 - phys_footprint_peak 318 / 312 -> 330 / 335 MB - heat, requests, overview 0/7/30 and stats 0/30 answers byte-identical A 16 MB room: 3:46.86 / 3:38.78 CPU, 1,554 / 1,390 collections, peak 331 / 323 MB, so it buys little. Tests (mote): go vet ./internal/gui; go test ./internal/gui -run 'TightGC|WarmUp|UnderTight|TightPercent|WarmCodex' ok. TestTightPercentLeavesRoom pins the bound; TestTightGCRetunesAfterACollection checks a collection retunes GOGC and the read's end restores it. Broken by hand: retightenGC not setting GOGC turns TestTightGCRetunesAfterACollection red. Not tried: the full gui package (TestCoveredWindowStaysUp is killed on mote, #4125); Windows and Linux runs. |
||
|
|
c7ae24f0a6 |
gui: the warm-up's usage read sets no memory limit, a cold start stops collecting nonstop (#2278)
The warm-up's QueryPage(All) and Codex effort ran under tightenGC(true): GOGC 25 and a soft memory limit at what Go held when the read began. On a cold start the heap reached that limit all live, and gctrace showed a collection every ~160 ms from ~11 s to ~24 s, heap = live = limit, about one core the whole time. Now the read takes GOGC 25 only, as a page's request already did, and tightenGC lost its limit parameter and heldMemory. Measured on mote (M5 Pro), cold start with no caches, 390k calls in usage.jsonl plus a growing Codex rollout, 10 endpoints polled every 5 s, 60 s each (coldx.sh: footprint each second, gctrace, ps cpu time): - before (v0.1.2111 head): CPU 3:39.33, 1166 GCs, phys_footprint_peak 855 MB - after: CPU 2:05.86 / 2:04.60 / 2:02.78, 618 GCs, peak 860 / 835 / 863 MB The cold start reads no request index, so it builds one from every session, the case the limit was added for; its peak is unchanged. Tests at this head, through mote-run: - go vet -tags nogui ./... for GOOS linux, windows and darwin: ok - go test -timeout 45m ./internal/gui/ ./internal/usage/ ./internal/sessions/: usage, sessions ok; gui only TestMainWindowCorners/macOS_26_SDK, #3949. TestUnderTightGCLimitsMemory became TestUnderTightGCSetsNoMemoryLimit; the old code set a limit below MaxInt64, so it would be red there (not run on the old code: tightenGC's signature changed). |
||
|
|
353519f557 |
gui: a Sessions or Usage poll's reads are collected under GOGC 25, and two reads under it at once put back what was set before
An open Sessions or Usage window polls every 15 s, and a poll's reads allocate ~330 MB to keep ~105 MB. At GOGC 100 the heap grew to twice what it kept before a collection, so Activity Monitor showed ~280-360 MB during each poll. Each /api/sessions* and /api/usage* GET now runs under GOGC 25, the warm-up's usage read's setting, without the memory limit that read also takes: held at heldMemory, every poll collected over and over and the window spent 5x the CPU. underTightGC put back what it found, so two reads at once ended with the second's 25 for good when the first ended first. A count now holds it: the first read sets GOGC (and the limit, for the warm-up), the last puts back what was there before the first. Measured in a sandbox HOME over the real session and usage data (6 GUI polls 15 s apart after a warm start, footprint right after each poll / 10 s later; CPU over the 6 polls): - origin/main: 326 326 326 290 364 281 MB / 188-217 MB; 5.2 s - GOGC 25 + memory limit: 190 176 172 161 216 186 / 149-172; 20.7 s - this (GOGC 25 only): 278 217 220 197 248 214 / 186-209; 5.6 s /api/sessions 495 ms vs 653 ms on main, the other routes the same. TestTightGCOverlappingReads ends two overlapping reads in either order; with the count taken out (each read putting back what it found) it is red, "one read still in flight under GOGC=100, want 25". Run at this head ( |
||
|
|
99de8e1ad1 |
gui: the warm-up's whole-history reads hold Go to the memory it held when they began (#3493)
A cold build of the request index (after any update that changes
internal/usage) reads every session again and allocates ~1.2 GB to keep
~40 MB more. Even under GOGC 25 the heap overshot its goal into pages it
kept, so a cold start peaked ~70 MB over a warm one. underTightGC now also
sets a soft memory limit at what Go holds of the system's memory when its
read begins (total mapped less released), and puts the old limit back
after. A lower limit the user set is kept, and GOGC off gets none.
Real data, 15.7k sessions (sbpairs: copies of the real cache/config, the
real Claude Code and Codex session folders linked read-only), harness
TestZZWarm running warmSteps under sessions.Warm, phys_footprint_peak,
old =
|
||
|
|
1414705159 |
gui: the warm-up's read of the whole usage history runs under GOGC 25, so a cold start peaks ~130 MB lower
The warm-up's last big read, the Usage page's QueryPage over all time,
holds every row of the history unpacked at once (129 MB of rows, 271 MB
live at that moment for this history), and at Go's default GOGC the heap
grows to twice what is live before collecting: Activity Monitor's
footprint peaked at 555-587 MB there, on a magpie that rests at ~200 MB
once it is done. underTightGC lets the heap grow by a quarter during that
read and puts back what was set; a GOGC the user set lower, or off, is
kept. Holding fewer rows at once needs the page built in passes over
packed chunks (rowRef points into unpacked ones), which is the next step.
The whole warm-up under GOGC 25 gave the same peak for ~11 s more CPU, so
only that read is.
Measured with startheap-runs/fp.sh: cold start (calls and sessions caches
deleted) of a 6,437-file history, phys_footprint sampled every 2 s and
footprint's own phys_footprint_peak at the end, run until the caches stop
growing for 30 s; every run wrote the same 6,437 files / 70,069,451 bytes.
Machine at load ~85-140 from other sessions.
before (
|