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 4179cf2d8 (pii: pf-serve-base for CPUs without AVX2; no file in common); not run again there.