Under -race sync.Pool lets a quarter of what is put in it go, so json's
encoders and regexp's matchers are made again: four gui tests bounding
what a path allocates went red under -race at fd70def82, and at the
base before it. TestProviderInfoReadsTheListOnce measured a row at 88
MB against 13 MB without -race, all in catalog.FamilyOf's regexps.
raceOn (as internal/gateway has it) now skips the bound in
TestStateWriteGrowsNoBufferItsSize, TestProvidersWriteGrowsNoBufferItsSize,
TestJSONRowsNotHeldWhole and TestProviderInfoReadsTheListOnce (after its
row checks). Without -race they run as before.
Run on mote at this tree:
- gofmt, go vet ./internal/gui, GOOS=windows and GOOS=linux go vet
-tags nogui: ok.
- The four tests without -race: PASS.
- go test -race ./internal/gui: only TestSettingsSaveKeepsWhatItDoesNotSend
(#4514) and TestMainWindowCorners (#3949) red, which are red without
-race too.
Picked onto 7da5b34aa (sessions, gateway); not run again there.
Each poll of the Agents page encoded the whole state (1.3 MB with real
accounts) into json's buffer, and the GC between polls empties the pool
that buffer comes from, so it grew to the state's size again each poll:
48 MB of what twenty rounds allocated (v0.1.2477 build, real-account
sandbox), and 68 MB at v0.1.2463.
writeStateJSON encodes the state without its agents twice (as sent, and
as keepState keeps it, without the settings), and each agent once,
straight to the response and to keepState's sha256, through one encoder.
keepState is split so the handler hands it that sum (keepStateSummed).
When the splice can't be made (no agents, or a field put before
"agents"), it writes and sums the state whole, as before.
Measured on this Mac with the real-account sandbox (abr.sh, 20 rounds of
drift + state + providers):
- v0.1.2477: writeJSON under /api/state 48 MB, 511 MB in all.
- this change: writeStateJSON 15 MB, 477 MB in all. The /api/state
bytes are identical to v0.1.2477's (cmp).
Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows.
- TestStateWrittenAsEncoded (same bytes as Encode, same sum as keepState,
for a large state, an empty agent list and none) and
TestStateWriteGrowsNoBufferItsSize, with TestKeptState* and TestLast*:
ok 3 of 3.
- Broken by hand (the whole-state path always taken): red, "writing a
1614586-byte state allocated 4207139 bytes, want under half its size".
- Not run before this push: the full internal/gui package; it runs next.