A start with the owner's real accounts (release build, mote) allocated
279 MB in its first seven minutes; three of the largest were buffers
the size of a whole document that nothing needed whole:
- yaml.v3's emitter appends every event to a queue it never empties,
so encoding dsh's route of a few hundred models held ~24 MB of
events (dshPutProviders' Node.Encode and dshNodeLines). That round
runs on the first start of each version and on each catalog change.
yaml.v3 is vendored in third_party/yaml.v3 (replace in go.mod, as
jsonschema is) with the queue started again once it is drained;
MAGPIE.md says what changed. go.yaml.in/yaml/v3 v3.0.5 has the same
queue.
- edit.TOMLWithout made its output as large as the input: 1.5 MB per
read of Codex's config, which five readers make, to keep a few KB
around the projects tables. It now grows to what is kept.
- catalog.fileKey read the ~6 MB catalog whole to hash it; it is now
hashed as it is read.
Measured with the owner's real accounts (~/r2278/acct, tray only, no
window), release ldflags and the footprint overlay, a version new to
the HOME so dsh's full round runs, on mote:
- allocations in the first 7 minutes 279 MB -> 260 MB;
yaml_emitter_emit 24.9 MB -> under pprof's cut (1.3 MB),
dshPutProviders 23.1 -> 8.1 MB, dshNodeLines 12 MB -> under the cut,
edit.tomlUnder 12.2 -> 4.0 MB
- footprint at +300 s 59 -> 58 MB, live heap 5.5 MB both; peak 84 vs
89 MB, within the run-to-run spread seen before (84-88 MB)
Run at this tree: upstream yaml.v3's own tests on the patched emitter
(go test ., ok); go test ./internal/agent ./internal/cli ./internal/edit
./internal/library ./internal/pluginrt ./internal/catalog on mica (ok),
and ./internal/sessions on mote before the yaml change (ok); go vet ./...
(mac), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...
ok; gofmt -l on the changed files prints nothing.
Not run: the full suite.
A Claude account's model list fetches models.dev again every 45
minutes (catalog.Asked), most often to the same bytes. Each fetch
rewrote models.json, so its mtime changed, and usage keyed its request
index, the index's file on disk (requests-v1.bin, heat, page, effort)
and its priced summaries on that mtime: the next usage query dropped
every chunk and read every session file again. On the acctp history
(15.7k session files) a start that rebuilds takes ~15 s of CPU in its
first 30 s, against ~2 s for one that keeps the index. Each fetch also
forgot the parsed catalog and told every agent to rewrite its list
(catalog.Changed), for nothing changed.
- catalog.CacheKey names models.json and labs.json by a hash of their
bytes, kept by their stat so a key costs a stat until a file changes.
Usage's request meta and price key use it in place of the mtime, as
liveListKey already did for the providers' lists.
- Sync writes models.json and labs.json only when their bytes changed;
the same bytes are dated now (Stale, Missing and Asked read the time),
and Reset and Touched run only when either file changed.
Tests: TestSameCatalogFetchedAgainChangesNothing (catalog) and
TestRequestStateKeptAcrossACatalogFetchedAgain (usage). Broken by hand:
with keepFetched always writing, the catalog test is red (told the
agents on the same bytes); with usage keyed on statKey again, the usage
test is red (meta and price key changed).