TestAlmaProvidersSeenDecodeOnce (v0.1.3114) went red in the whole
internal/agent package on mote: 401 allocations against its bar of 400,
green alone. testing.AllocsPerRun counts every goroutine's allocations,
and another test's watcher or poll left running lands in a round now and
then. leastAllocs takes the fewest of five rounds, which such a stray
reaches in one round, not in all five; leastBytes does the same for
bytes (runtime.MemStats TotalAlloc).
Run (mote, at this tree):
- gofmt -l internal, go vet ./..., GOOS=windows and GOOS=linux go vet
./internal/agent/ ./internal/provider/: clean
- go test -count=1 -timeout 45m ./... (all three commits' tree): 85
packages ok, internal/gateway 748s, internal/provider 193s. Two red:
internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's macOS 27
(#3949, filed before, untouched here), and internal/agent's
TestCodexEffortOptionsReadTheKeptList, whose bar counted the
environment's copy (see the effort test's comment), fixed in its test.
- then go test -count=1 -timeout 45m ./internal/agent/ with that fix:
ok (200.1s)
Broken by hand: with the bytes.Equal check in almaProvidersSeen removed
the look measures 7232 allocations and goes red, as before.
almaProvidersSeen decoded Alma's providers list each time it was asked
past almaReadFor, on each poll of the Agents page. On the live magpie
(v0.1.2906) Alma's answer is 227 KB, and its json.Unmarshal was ~13 MB of
what an idle two minutes allocated (heap profile diff from
/v1/magpie/heap). The same bytes are now answered with the providers they
gave last time, by pointer or by bytes.Equal; changed bytes are decoded
as before.
Run (mote, at this tree):
- go vet ./internal/agent/, gofmt -l: clean
- go test -count=1 -timeout 45m ./internal/agent/: ok (216.6s)
- TestAlmaProvidersSeenDecodeOnce's new part (almaReadFor 0, AllocsPerRun of a
look) is green at most 400 allocs; with the bytes.Equal check removed
by hand it measures 7232 and goes red.
Not tried: a live Alma app against this build; the bytes compared are
what almaGet already returned.
A heap profile of the live magpie (v0.1.2646, 37 minutes, the owner's
real accounts) had almaProvidersSeen decode Alma's whole /api/providers
answer 390MB worth: the Agents page's model field (almaGet, 221MB) and
Alma's check (alma.func1, 167MB) each decoded the answer almaSend
already kept for 5s, every poll.
almaProvidersSeen keeps the slice it decoded beside the bytes it decoded
it from, and gives it again while almaSend gives the same kept bytes. A
new answer (5s on, or any change sent to Alma, which forgets the kept
ones) is decoded anew; a failed read is an error, never the last good
answer. Its three callers only read what it gives.
Run on mote (macOS 27.2):
- TestAlmaProvidersSeenDecodeOnce (new): 400 known models; 10 allocs or
fewer a look, one ask of Alma, the new models after a PUT, an error
with Alma gone. With the bytes check turned off by hand: "a look at the
answer kept allocates 6833 times", red. Restored: ok.
- The owner's real Alma answer (227KB with keys blanked, 11 providers,
539 models; probe not committed): a look 1,182,317 B / 30,690 allocs
before, 48 B / 1 after.
- go test ./internal/agent: ok (161.6s); -race -run TestAlma: ok.
- gofmt -l clean; go vet, GOOS=windows and GOOS=linux go vet: ok.