Commit Graph
1 Commits
Author SHA1 Message Date
yetone ecd0638276 gui: the Sessions list is encoded once, into the answer it is sent as
writeJSONRows marshalled each row on its own, joined the rows, and wrote
the join into a buffer that grew from nothing: three copies of the ~8 MB
list on every 15 s poll. The rows are now encoded straight into the
answer, whose buffer is made the size of the last answer of that key;
each row's bytes (for its sum and for a delta) are a slice of it. The
answer is byte for byte what it was, so tags and deltas are unchanged.

A/B on the same live history (rss-bin ab5.sh, 8 polls 15 s apart,
11dcc743f vs this): writeJSONRows 224MB -> 126MB allocated, json.Marshal
128MB -> 30MB. Total allocation in the second run was higher, all of it
in usage's readRequestBlocks/s2.Decode (a usage block rebuild of the live
data during that run), which this path doesn't reach; footprint per poll
is within the runs' noise.

New TestWriteJSONRowsWritesWhatMarshalDid compares the answer with the
old construction for 0..3 rows (HTML, U+2028, quotes, newlines, 1e21),
with and without other fields, twice each so the second uses the sized
buffer, and checks a delta's changed row and runs. Broken by hand
(a row's slice keeping its comma) it goes red on the delta.

Run at this head (rebased on 11dcc743f, origin/main fetched): gofmt
clean; go vet -tags nogui ./internal/gui/ on linux, windows, darwin ok;
go test -count=1 -timeout 45m ./internal/gui/ ok (234s).
Not run: the other packages (only internal/gui changed) and the GUI JS
suite (no asset changed).
2026-10-27 13:11:16 +08:00