ac4af582301a4e8a29245dbba767eba31334ddf9
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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 |
||
|
|
b3642e7277 |
sessions: a dsh session read before is read on from where it was left, not whole
dsh only appends to a session file, a line at a time or, packed
(.zstd), a frame of lines at a time. Every reply still made the
Sessions and Usage pages read, and for a packed file decompress, the
whole file again: a packed file "can't be read on from the middle of a
frame".
It can be read on from the start of one. frames.go walks a file of zstd
frames without decoding them (RFC 8878: the frame header, then blocks
that each give their length, then the checksum), decodes one frame at a
time, and says where to go on from: the frame the first line not yet
whole starts in, and how far into what it holds. A frame not yet
written whole waits for the next read, and so does a line a frame ends
inside of.
parseDsh keeps a tail (tail.go) and the header it read, and counts each
event as it comes (dshCount) instead of collecting them all first. A
fork's inherited end-seed met in a later read starts the counts over
from the session's start, keeping its title and name, as the whole read
did by cutting at the last one. A file that shrank or was replaced is
read whole again. One change from before: a last line not ended by a
newline now waits for it, like every other appended file's.
Measured (CPU, getrusage; 50 MB of events, a reply appended between
reads; packed: 17 MB of frames; machine loaded):
plain before: ~110-120 ms per read after an append
after: 0.4-2.6 ms per read after an append; first read ~120 ms
packed before: ~190-250 ms per read after an append
after: 0.4-0.5 ms per read after an append; first read ~260 ms
Tests: TestDshReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases.
TestDshPackedReadsOnlyWhatWasAppended appends a frame (read alone), half a frame (waits), a
frame ending inside a line and the frame that ends it (read on from the
first of the two, the line counted once), then cuts the file short and
replaces it with a longer one (read whole). TestDshEndSeedAcrossReads
writes a fork's seeded lines, its end-seed and its own, a read apart
each. Every read on is checked equal to a whole read.
Broken by hand: resume off -> red in both ReadsOnly tests ("after a
line appended to 1308 bytes, read from 0", "after a frame appended to
654 bytes, read from 0"); a line split over two frames resumed at the
second frame -> red (read on differs from whole); the end-seed reset
removed -> red in TestDshEndSeedAcrossReads and TestDsh.
Run: go test ./internal/sessions -count=1 -timeout 45m ok; gofmt -l
and go vet ./internal/sessions clean. The full-suite record is in the
last commit of this series.
|
||
|
|
e03d495f83 |
sessions: a Kimi Code session read before is read on from where it was left, not whole
Kimi Code only appends to a session's wire.jsonl, but every message (and
every rewrite of its state.json, whose size and mtime are folded into
the wire's) made the Sessions and Usage pages read the whole wire again,
a fork's twice: once for its last marker, once to count.
parseKimi is now one pass that keeps a tail (tail.go) and what the read
carries on with: the session's start, whether it is a fork, and the
fork's marker time. A forked marker met in a later read starts the
counts over from it, as a whole read does. Title, cwd and name still
come from state.json on every read, so a state.json-only change reads
none of the wire. A forkedFrom set or cleared reads whole again, and so
does a wire that shrank or was replaced; a half line waits.
Measured (CPU, getrusage; 50 MB wire, a message appended between reads;
machine loaded):
before: ~256-278 ms per read after an append (same as the first read)
after: 0.3-0.6 ms per read after an append
Tests: TestKimiReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases on a real wire's events,
then a state.json title change (nothing of the wire read) and a
forkedFrom set (read whole). Every read on is checked equal to a whole
read. TestKimiForkMarkerAcrossReads writes a fork's copied lines, then
its marker, then its own usage, a read apart each: only the fork's own
usage counts.
Broken by hand: resume off -> red ("after a line appended to 29089
bytes, read from 0"); the marker's reset removed -> red in
TestKimiForkMarkerAcrossReads and TestKimiCodeSessionFork.
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
b9b4c21c5b |
sessions: a Droid transcript read before is read on from where it was left, not whole
Droid only appends to a session's transcript, but every message (and
every rewrite of its settings.json, whose size and mtime are folded into
the transcript's) made the Sessions and Usage pages parse the whole
transcript again.
parseDroid now keeps a tail (tail.go) and what the read carries on with:
whether the session_start line and a fork's copied lines are behind it,
and what the settings' running total was counted as (date, model,
tokens). The next read takes that total back (dropUse, which leaves no
empty model or day behind, so the summary is the one a whole read makes),
reads on from the tail, and counts the total again on the day of the last
message. A transcript that shrank or was replaced is read whole again; a
half line waits for the next read.
Measured (CPU, getrusage; 50 MB transcript, a message appended between
reads; machine loaded):
before: ~490 ms per read after an append (same as the first read)
after: 0.2-1.8 ms per read after an append; first read ~470 ms
Tests: TestDroidReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases, then a message a day later
with a grown total (counted once, moved to the new day), then a
settings-only change (nothing of the transcript read). Every read on is
checked equal to a whole read. TestDroidForkAcrossReads appends a fork's
copied lines one read at a time.
Broken by hand: resume off -> red ("after a line appended to 825 bytes,
read from 0"); the old total not taken back -> red (read on differs from
whole).
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
d9f6b42cbc |
sessions: a Grok Build session read before is read on from where it was left, not whole
Grok Build only appends to a session's updates.jsonl, but every change
to it (and every rewrite of its summary.json, whose size and mtime are
folded into the file's) made the Sessions and Usage pages parse the
whole file again.
parseGrok now keeps a tail (tail.go) with its summary: the offset after
the last whole line, the file's head and a sampled prefix hash. The next
read goes on from that offset when the file has only grown and the
summary still names the same model, created time and parent; the first
prompt still coming in chunks carries over too. A file that shrank, or
whose head or sampled prefix changed, is read whole again, and a half
line at the end waits for the next read.
Measured (CPU, getrusage; 50 MB updates.jsonl, a turn appended between
reads; the machine was loaded, so CPU time, not wall):
before: 46 ms per read after an append (same as the first read)
after: 0.2 ms per read after an append; first read 44 ms
Tests: TestGrokReadsOnlyWhatWasAppended checks where each read starts
(through scanHook) and that every read on from a tail equals a whole
read: a line appended is read alone; half a line waits and is counted
once; the file cut back to its old bytes, or one byte changed in place
in a line it had, is read whole; a summary-only change reads nothing of
the updates; a changed model reads whole. TestGrokPromptAcrossReads
carries a chunked first prompt across reads.
Broken by hand: resume turned off -> red ("after a line appended to
2684 bytes, read from 0"); tail.holds made to trust any grown file ->
red ("rewritten in place, read from 3055").
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|