ac4af582301a4e8a29245dbba767eba31334ddf9
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b8270850df |
sessions: a kept parse's rarely set fields live in a StateMore made only when one is set (#2278)
Each of the ~18k files the Sessions cache keeps had a 760-byte state, and ~330 bytes of it were fields almost no file sets: the Codex spawn and agent maps, Named/Custom/First, the dsh and Claude conversation lists, Root/Leaf, Compacts, and the six per-agent tails (Grok, Droid, Kimi, Agy, Dsh, Cline). On the owner's real cache (18,331 files) Root and Leaf are set in 150, Named in 117, Compacts in 78, First in 35. They move to an embedded *StateMore, nil unless something is in it: reads go through more() (a shared empty one when nil), writes through own(). The JSON is the same (embedded fields are inlined), so the cache version stays. - parseWith drops an extra that only had empty values written to it, and share() drops one the decode made empty. - clone() deep-copies the extra, so growing a clone leaves the kept state alone. Copies that never write (withoutRevisions, the Agent rename) share it, as they shared the maps before. Run on mote at this tree: - gofmt -l internal/sessions: clean. go vet ./internal/sessions/ on darwin, GOOS=linux and GOOS=windows: ok. - go test -count=1 ./internal/sessions/: ok (26s). - Every selector was checked by renaming the embedding to a named field and compiling with -gcflags=-e until only the struct literals were left, so no field is reached through a nil *StateMore. - New tests in state_more_test.go: zero() knows every field (reflect), a read makes no extra and a write never reaches the shared empty one, a clone owns its extra, and a cache round trip keeps no empty extra. Broken by hand: dropping Cline from zero() and sharing the extra in clone() each turn their test red; restored. - Real-account idle heap (copy of the owner's config and 24.6MB sessions cache, gateway idle 180s, heap after GC): decodeCache's retained heap 35.0MB -> 22.5MB, reflect.unsafe_New 20.0MB -> 10.5MB. The total (128.7MB -> 133.6MB) moves by more than that between runs of one binary (118-140MB), from late passes that happened to be live. Not tried: the full ./... suite (state is unexported; only internal/sessions uses it, and the whole binary builds). |
||
|
|
c07ca663cd |
sessions: a change to one agent's parser reads that agent's files again, not every file (#2278)
cacheVersion was raised 7 times since 10-28, three on 10-30 alone, each
for one agent's parser (Claude Desktop's entrypoint, Droid's skills,
OpenCode/Cline/dsh tool calls...). Each raise threw the whole kept index
away, so every user's first start after the update read their whole
history again: on the 52GB Codex + 13GB Claude Code history on mote,
~4 minutes of CPU and the fans on, the slowness users report after an
update.
Now each kept parse names its agent, the index keeps parseVersions as
they were (Parsers), and decodeCache drops only the parses of an agent
whose version moved. A change to one agent's parser raises
parseVersions[agent]; cacheVersion stays for changes to the index
itself. An index kept by an older magpie names no agents: its parses
stand while no version has moved, and refresh names them on the next
read (a copy, as readers hold the old one) and saves, so a later raise
keeps them too.
Not changed: calls-vN (call_cache.go) still names one version for every
agent's call shards; it was raised once since 10-01.
Run on mote (Go 1.26.8):
- gofmt clean; go vet ./internal/sessions ./internal/usage ./internal/gui
for darwin and windows, ./internal/sessions ./internal/usage for linux:
ok
- go test -count=1 ./internal/sessions ./internal/usage: ok
- go test -race -count=3 -run TestParseVersion ./internal/sessions: ok
- Broken by hand: decodeCache keeping every parse makes both
TestParseVersionsReadOneAgentAgain and
TestParseVersionRaiseReadsThatAgentAlone red; refresh not naming an
old index's parses makes the latter red (read claude:3 codex:2).
Real history (the 52GB Codex + 13GB Claude Code copy, 16,619 kept
parses, index left by v0.1.2314), warm starts, 75s each:
- v0.1.2314: 10.7s CPU, 275MB peak
- this change, first start on the old index: 13.7s, 259MB; nothing
read again, all 16,619 parses named and saved
- the same with parseVersions{"claude": 1}: 47.0s, 269MB, Claude Code's
files alone read again (a cacheVersion raise: ~4:00)
- the next start: 13.2s, 261MB
- heatmap, requests, overview 0/7/30 and stats 0/30 answers
byte-identical to v0.1.2314's in every run.
|
||
|
|
bbb4fd478a |
sessions: a parse's models, days and tools are sorted slices, not maps
A kept parse holds a model or two, a day or two and a few tools, and Go's map of one entry is a whole group of eight: ~500 bytes for one model's Tokens, where a sorted slice entry is 56. Over a long history (15.9k kept parses) state.Models, Days, day.Models, Tools and Skills held 18.4MB as maps and 4.2MB as named[V], a slice kept in name order. It is written as the same JSON object a map writes, byte for byte, so the parse cache saved before reads unchanged; names are interned with unique.Make, and plain integers in ints and Tokens are read without reflection. Measured with the real ~/.codex and ~/.claude histories (sandbox HOME, warm cache, 40s after start), base |
||
|
|
13f9070135 |
sessions: a kept file of one day holds that day's models once (#3493)
A long history's kept parses held 28MB live after a start's decode of
sessions.json (15,624 files). 15,345 of them have exactly one day, and
that day's model map is the file's own, so every such file held two
equal maps of ~700B each. decodeCache's share now points the day at the
file's map when they are equal.
A kept state is never written: use, unuse and dropUse are the only
writers of Models, and every parser (sessions.go, calls.go, calls_dsh,
dsh, droid, grok, kimi, cline) writes a clone, which copies the two
maps apart.
Run, at this head on
|
||
|
|
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 (
|
||
|
|
94503901c0 |
sessions: a string many kept files repeat is held once
decodeCache's Unmarshal made a string for every file's title, cwd and model names, however many files gave the same one. On the real history copy (sbpairs, 27,699 kept files) 23,689 sessions a script ran carry one ~420-byte prompt as their title. The kept parses held 54 MB after a collection, 11 MB of it such copies. Each decode worker now takes those fields (title, cwd, first, named, model, provider, msg_model, msg_day, codex_nickname, and the Codex identity's role and parents) through unique.Make, so the parses hold 44 MB. The decode took 104-114 ms, as it did (121 ms when measured for |
||
|
|
e2dbb03405 |
sessions: the kept parses are decoded on a few goroutines at start
One json.Unmarshal of sessions.json (40MB, 27,679 files on a long
history) took 310 to 440ms of every start before the first page (#3493).
decodeCache checks the file is valid JSON (gjson), reads its version and
zone, splits the files without copying them, and decodes each file's
parse with json.Unmarshal on up to 8 goroutines. The result is what one
Unmarshal gave: a key given twice is its last, and the file is refused
where it was refused (bad JSON, another version or zone, no files, a
parse that doesn't decode). Only the keys are copied out of the read.
Real data (sandbox copy of the live sessions.json, load ~60): Unmarshal
311ms, decodeCache 121ms, reflect.DeepEqual the same 27,679 parses.
Run at
|