Commit Graph
2 Commits
Author SHA1 Message Date
yetone e364d27fce agent, provider, profile: a state poll builds no agents per profile, keys dsh entries without joining them, and works out renames once a change
What /api/state still allocated with real accounts, forty polls on mote
(t29, 76 and 83 MB):

- profile.Details built every agent again for each profile listed
  (7 MB). DetailsIn takes the agents the page already holds for its
  request; Details keeps its signature for other callers.
- dshNodeShared joined an entry's lines into a string to key its parsed
  node (5.7 MB). It now hashes the lines with maphash and checks them
  against its own copy, so a hit allocates nothing; a caller changing
  its slice in place still gets the new text.
- dsh's Joined check read and parsed the first profile's list each poll
  (5.2 MB). It uses dshLook, the parse shared until the file changes;
  dshOver only changes a copy of the items.
- provider.UsageRenames parsed the whole providers.json for each
  profile's in-use check (5.1 MB). It is worked out through filememo
  once per change; a file that doesn't decode goes through read's own
  last-good path as before.

Measured on mote, sandbox HOME with the owner's real account data, 5
warm-up then 40 calls, paired runs:
  /api/state  t29 82.9 / 76.0 MB  ->  t30 38.1 / 47.4 MB  (-46%)
  /api/drift  t29 7.3 / 5.5 MB    ->  t30 9.7 / 7.1 MB (512 kB sampling
              noise: no dsh or renames frame in either top list)

Tests:
- TestUsageRenamesParsedOnceAChange: 60 providers, a look at unchanged
  renames allocates at most 10 times, a rename since shows at once.
  Red on the old rename.go (424 allocations).
- TestDshLookParsesAnEntryOnce now asks dshNodeShared alone for 0
  allocations and checks a slice changed in place. Red on the old
  dsh.go (1 allocation).

Run on mote at this tree: gofmt -l clean; go vet of agent, provider,
profile, gui; go test -count=1 of internal/agent (390s), provider
(256s), profile, gui (174s) and usage: all ok.
Not run: the full ./... suite and the GUI (JS) suite; no JS changed.
2026-11-10 07:36:19 +08:00
yetone 35c47f762f agent: the window's drift poll parses dsh's YAML once per change, not per field and per look
The window asks /api/drift every 15s. On the owner's live magpie a heap
profile showed Drift and Values allocating ~3.3 GB in 37 minutes, most
of it DeepSeek Harness: settings.yaml (80 KB) parsed again for each
field GetYAML read (465 MB of it), and each profile entry's YAML parsed
again on each of dshCheck's looks (dshHomeHas, dshOver, dshConfigIndex,
dshRoutesIn, dshConfig).

- edit.loadYAML memoizes the parsed root through filememo, keyed by the
  file's stat, and shares it with GetYAML, GetYAMLMap, GetYAMLList and
  GetYAMLText, which only read it. Writes go through their own parse as
  before. BlockList skips the decode for a text that starts as a block
  list (blockSequence), which every dsh patch list does.
- dshNodeShared parses an entry's text once and shares the node with the
  read-only lookers (dshConfig, dshConfigIndex, dshRoutesIn, dshOver's
  patch side). The writers (dshOver's base, the route and start writes)
  keep dshNode's own copy. 512 entries kept at most.

Run on mote (macOS 27.2):
- Probe on copies of the owner's real ~/.dsh (settings.yaml, config.yaml,
  the desktop and web profiles; probe not committed, copies deleted):
  a.Values() + a.Drift() per poll, 20 polls: 16381 KB / 223788 allocs
  per poll with the edit change alone -> 4355 KB / 2588 allocs.
- TestGetYAMLParsesTheFileOnce (new): a look at a 3000-entry file
  allocates under a tenth of its size; sees SetYAML, another process's
  write, a removed file and a list-topped file.
  TestBlockSequenceAgreesWithADecode (new): ~24 texts against yaml's own
  decode.
- TestDshLookParsesAnEntryOnce (new): with dshConfig and dshConfigIndex
  put back on dshNode by hand: "27388 allocations, want a few", red.
  Restored: ok. It also checks a writer's change never shows in a look.
- go test ./internal/agent ./internal/edit: ok (164.2s, 5.9s).
  go vet both: ok. gofmt -l: clean.

Not tried: the full suite (only internal/agent and internal/edit
call these); a live window poll after the release.
2026-11-02 06:30:12 +08:00