Files
magpie/internal
yetone 89dc164765 sessions: sessions.json is written a file's parse at a time
A save marshalled the whole index into one buffer: 22.8MB for a long
history (15,624 files), grown by doubling to ~85MB of allocation a save,
and a save follows every refresh that read a changed session file, so a
start while agents run, and a Sessions or Usage poll after any call. It
is written through a json.Encoder into a 256KB buffer handed to a 1MB
bufio.Writer on the temp file, keys in json.Marshal's order and escaped
as it escapes them, so the file is the same bytes.

Measured on the real sessions.json (sbpairs, 22,836,803 bytes):
json.Marshal 54-73ms and 85MB alloc; encodeCache 51ms and 14MB alloc;
the output equal byte for byte.

Run at this tree (3767addd4 + the race skip + this change):
- go test -race -count=1 ./internal/sessions: ok
- go test -count=1 ./internal/sessions ./internal/usage ./internal/gui
  ./internal/agent/...: ok
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions: ok;
  gofmt -l clean
- TestEncodeCacheIsMarshal compares with json.Marshal for 3002 files (a
  key and a title with <, &, quotes and U+2028, a file of no parse), an
  empty index and none. Broken by hand (keys in map order): red; restored:
  green.

Not tried: the save on Windows or Linux.
2026-10-25 07:17:17 +08:00
..
…
…
…
…
…
…