Commit Graph
1 Commits
Author SHA1 Message Date
yetone 4d1ec346aa edit: a JSON file is made plain JSON once a read, not on every look
GetJSON, GetJSONRaw and GetJSONItem copied the file and ran jsonc.ToJSON
over it on every look. The window's polls look up agent settings many
times a round, so twenty polls allocated 80 MB in that conversion alone
(heap profile of a real-account sandbox).

jsonHeld keeps the plain-JSON bytes in filememo, keyed by the file's
mod time and size, so a look reads them shared. gjson.GetBytes copies
what it returns, so nothing a caller gets aliases the held bytes. A
write (SetJSON and the rest) changes the file, and the next look reads
it again.

TestGetJSONConvertsTheFileOnce: a 290 KB JSONC file with a BOM, 20
looks must each allocate under a tenth of the file, and a value set
afterwards is seen. Red on the old code: 296 KB a look.

Run at this head:
- mote: go vet (darwin, GOOS=windows, GOOS=linux) ok; go test
  ./internal/edit ok, and ok under -race.
- WSL (magpie-desktop): internal/edit ok, internal/provider ok;
  internal/agent red only in TestInstalledVersion, TestHowInstalled,
  TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir, the install-detection reds of #4033.
2026-11-01 04:04:50 +08:00