Commit Graph
2 Commits
Author SHA1 Message Date
yetone fd70def825 gui: a Providers poll sums what it keeps while writing the answer
Each poll of /api/providers encoded the answer for the page and then
encoded the kept last-known list again only to sum it (keepProviders,
encodedSum): 32-34 MB of what forty polls allocated with real accounts.

writeProvidersJSON now returns the encodedSum of keptProviders(s), taken
from the same encoding, as writeStateJSON does for /api/state. A row
kept as it is (no headers, proxy, extra body or account proxies) is
encoded once into the answer and the sum; only a row with those is
encoded again without them. The head and tail of the kept file come
from marshaling it with no rows. A nil row list, or a head that doesn't
match, falls back to the old writeJSON and encodedSum. The other
keepProviders callers (after a save) are unchanged.

Run on mote at this tree:
- gofmt, go vet ./internal/gui, GOOS=windows go vet -tags nogui: ok.
- go test -run 'Providers|Kept' ./internal/gui 3 times alone: ok.
- New TestProvidersWriteSumsWhatIsKept: the sum equals
  encodedSum(keptProviders(s)) for bigProviders, rows with each secret
  field, gateway calls, moved models, and empty and nil lists. Broken
  by hand twice: keepsAllOf always true (secrets summed) and the kept
  tail left out of the sum. Red both times.
- go test ./internal/gui: only the known reds,
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949).
- -race -run 'Providers|Kept': TestProvidersWriteGrowsNoBufferItsSize
  red, and red the same way at the base (c76bcaea7, twice): an
  allocation count under -race, where sync.Pool drops items. Fixed in
  its own commit next.

Real accounts, sandbox HOME, 40 polls of state, providers and drift,
v0.1.2509 (msteady) vs this (mpsum), two rounds each:
- alloc_space shown: 365.6/364.3 MB -> 341.5/329.8 MB; keepProviders
  32.9/32.1 MB -> gone; writeProvidersJSON 15.3/13.6 -> 9.9/14.9 MB.
- poll CPU 4.21/4.27 s -> 4.18/4.10 s; footprint peak 111/116 ->
  112/108 MB.
- /api/state and drift answers byte-identical; /api/providers differs
  only in the providers' "fetched" time.

Not run: the Linux and Windows apps; a save's keepProviders path is
unchanged and was not exercised.
2026-11-01 09:04:26 +08:00
yetone 573b21f4b0 gui: the Providers answer is written a provider at a time
Each poll encoded /api/providers whole, growing json's buffer to the
answer's size once the GC had emptied its pool. writeProvidersJSON
writes the same bytes with each provider's row encoded alone, as
writeStateJSON does for agents; every handler that answered
writeJSON(rw, providersState()) uses it.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls, bb478f0e5 (mshare) vs this tree (mall):
  the providers write 37.7 MB (writeJSON, cum) -> 13.6 MB
  (writeProvidersJSON, cum)
  /api/providers equal but for `fetched` and `lapsed` (a refused
  refresh in the blocked sandbox); /api/state and drift identical

TestProvidersWrittenAsEncoded: the bytes are json.Encoder's for a big
answer, an empty list and none. TestProvidersWriteGrowsNoBufferItsSize:
under half the answer's size allocated per write. Broken by hand on
mote (writeJSON put back): "writing a 549015-byte answer allocated
2101096 bytes, want under half its size".

Run on mote at this tree: gofmt; go vet darwin and windows; the new
tests with TestStateWritten* 3/3 ok; go test ./internal/gui: the known
reds #4514, #3949 and TestColdTurnsTaken (#4510). GOOS=linux go vet of
internal/gui can't run here (Wails' Linux files need cgo; WSL has no
gtk4/webkitgtk-6.0); this change has no OS-specific code.
Not run: the full ./... suite.
2026-11-01 06:16:35 +08:00