usage: a session file's few calls are kept packed too
pack left a chunk of fewer than 64 rows as rows. Most session files hold a handful of calls, so a cold build (the first start after an update, or with no requests-v1.bin) kept 13,972 of 15,624 local chunks unpacked: 98,320 rows. The same chunks read back from requests-v1.bin are all archives, so the cold build alone held them as rows. Now every chunk with a row is packed when its archive is smaller, as the file's entries already were. Measured on the real history copy (sbpairs: 15.6k session files, 420k calls), one QueryPage(All) from cold under GOGC=25 as the GUI's warm-up runs it, three runs each, old then new: - heap in use after: 267/267/269 MB -> 229/227/232 MB - peak heap in use: 357/367/341 MB -> 308/338/336 MB - max RSS: 454/462/448 MB -> 420/424/449 MB - page: 2.95/2.41/2.52 s -> 3.66/2.19/2.42 s (no change past noise) A page after a new call, packed chunks read from the file: 120-143 ms, as before. TestFewRowsArePacked packs three rows and reads them back. It is red with the old 64-row floor. Run at this head: go test ./internal/usage (ok); go test -run 'Usage|Request|Tray|Session' ./internal/gui ./internal/gateway (ok); go vet ./internal/usage, GOOS=linux and GOOS=windows -tags nogui; gofmt -l. Not run: the full suite (one per machine).
This commit is contained in:
@@ -60,3 +60,22 @@ func TestPackedArchiveHoldsOnlyItsBytes(t *testing.T) {
|
||||
t.Fatalf("read back %q and %q", ua.row(99).Model, ub.row(99).Model)
|
||||
}
|
||||
}
|
||||
|
||||
// A block of a few rows is packed too: most session files hold a handful
|
||||
// of calls, and a started magpie kept ~14k of them unpacked, ~98k rows
|
||||
// and ~38 MB more than the same blocks read back from requests-v1.bin.
|
||||
func TestFewRowsArePacked(t *testing.T) {
|
||||
now := time.Now()
|
||||
c := &rowChunk{}
|
||||
for i := range 3 {
|
||||
c.add(Row{Record: Record{Time: now.Add(time.Duration(i) * time.Second), Agent: "codex", Provider: "openai", Model: "gpt-5.5", Input: 1200 + i, Output: 300, Session: "s"}}, fmt.Sprint("msg", i), int64(i), false)
|
||||
}
|
||||
packed := c.pack()
|
||||
if len(packed.Archive) == 0 || packed.Rows != nil || packed.Bytes >= c.Bytes {
|
||||
t.Fatalf("3 rows: archive %d bytes, %d rows kept, %d bytes for %d", len(packed.Archive), len(packed.Rows), packed.Bytes, c.Bytes)
|
||||
}
|
||||
back := packed.unpack()
|
||||
if back == nil || len(back.Rows) != 3 || back.row(2).Input != 1202 || back.row(2).Model != "gpt-5.5" {
|
||||
t.Fatal("3 rows: not read back")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ var rowDecodes = sync.Pool{New: func() any { return new([]byte) }}
|
||||
var rowEncodes = sync.Pool{New: func() any { return new([2][]byte) }}
|
||||
|
||||
func (c *rowChunk) pack() *rowChunk {
|
||||
if c == nil || len(c.Rows) < 64 || len(c.Archive) != 0 {
|
||||
if c == nil || len(c.Rows) == 0 || len(c.Archive) != 0 {
|
||||
return c
|
||||
}
|
||||
encoded, locations := c.encode(func(encoded []byte) bool { return int64(len(encoded)) < c.Bytes })
|
||||
|
||||
Reference in New Issue
Block a user