Every Sessions poll encodes all ~17k rows for their hashes, even when
the page already has the answer. enc.Encode(rows[i]) boxed each row
into an any, a copy allocated per row per poll. &rows[i] encodes the
same bytes (no type in sessionJSON has a pointer-receiver marshaler)
without the copy.
TestJSONRowsNotCopiedEach: a 2000-row poll the page already has makes
at most 200 allocations. Broken by hand (back to rows[i]): red, "made
2022 allocations". TestWriteJSONRowsWritesWhatMarshalDid still checks
the bytes against json.Marshal per row.
Measured on mote's build against the real ~17k sessions (sandbox HOME,
APFS clones), 30 polls, heap diff alloc_space:
writeJSONRows 201 MB -> 98 MB
whole poll 854 MB -> 726 MB
CPU over 30 polls 4.46s -> 4.44s (no change past noise); /api/sessions
median 74ms -> 73ms.
Run on mote: go test -run JSONRows ./internal/gui ok.
Not run: the full suite (one-line change in writeJSONRows, its tests
run).
Then rebased onto 586b59fe7 (provider: Devin's plugin min); not rerun.
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).