usage: the serials sourceDigest met go when idle
sourceDigests.by and .last, the serials met this turn and the one
before, stayed for the life of the process: 577 KB of a real history's
idle heap. They only order which digests heat-digests.bin keeps first
when there are more than it holds (2*65536, against ~17k session
files). dropDerived, the 3-minute idle drop, now writes what was made
and lets them go; sourceDigest notes a read (derivedUsed) as the other
per-chunk caches do.
TestDigestTurnsGoWhenIdle: the turn's serials are nil after the idle
drop and the next key hashes nothing again. Red with the nil-ing taken
out by hand ("kept 1 and 0 serials when idle").
Run at this commit on mote (load 23.7, over its 18 cores; mica's disk
was full): go vet for darwin, linux and windows ok; go test
./internal/usage ok (52s), ./internal/gui ok (132s). Real Codex history
in a sandbox HOME (~/r2278), page open 30s then 8.5 min idle: liveHeap
13.13 MB against 13.68 MB before; the heap diff shows sourceDigest's
577 KB gone. Not run: the full suite.
This commit is contained in:
@@ -78,6 +78,24 @@ func dropDerived() int {
|
||||
heatBefores.by = nil
|
||||
heatBefores.Unlock()
|
||||
n += dropEffortPeriods()
|
||||
n += dropDigestTurns()
|
||||
return n
|
||||
}
|
||||
|
||||
// dropDigestTurns lets go of the serials sourceDigest met this turn and
|
||||
// the one before (577 KB of a real history's idle heap). They only order
|
||||
// which digests heat-digests.bin keeps first when there are more than it
|
||||
// holds; what was made is written out before they go.
|
||||
func dropDigestTurns() int {
|
||||
sourceDigestsSave()
|
||||
d := &sourceDigests
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
if len(d.made) != 0 { // made meanwhile: written with them next time
|
||||
return 0
|
||||
}
|
||||
n := len(d.by) + len(d.last)
|
||||
d.by, d.last = nil, nil
|
||||
return n
|
||||
}
|
||||
|
||||
|
||||
@@ -121,3 +121,43 @@ func TestSourceDigestsKeptAcrossStarts(t *testing.T) {
|
||||
t.Fatalf("kept %d, want 1", got.len())
|
||||
}
|
||||
}
|
||||
|
||||
// The serials a turn met go when idle, after what was made is written:
|
||||
// the next key hashes nothing again.
|
||||
func TestDigestTurnsGoWhenIdle(t *testing.T) {
|
||||
pageHome(t)
|
||||
cut := time.Date(2026, 9, 28, 0, 0, 0, 0, time.UTC)
|
||||
d := heatDiskRef{root: "r", meta: "m"}
|
||||
c := &rowChunk{serial: 1<<63 | 7}
|
||||
c.Source.Agent, c.Source.Key, c.Source.Path = "codex", "k", "/s/7"
|
||||
c.add(Row{Record: Record{Time: cut.Add(-time.Hour), Agent: "codex", Model: "m", Input: 3}}, "msg", 1, false)
|
||||
sourceDigests.Lock()
|
||||
sourceDigests.by, sourceDigests.last, sourceDigests.made = nil, nil, nil
|
||||
sourceDigestsDisk.path, sourceDigestsDisk.kept, sourceDigestsDisk.mapped = "", nil, nil
|
||||
sourceDigests.Unlock()
|
||||
key := func() (string, int) {
|
||||
sourceDigests.Lock()
|
||||
was := sourceDigestsHashed
|
||||
sourceDigests.Unlock()
|
||||
k, ok := heatSettledKey(d, cut, time.Time{}, Filter{}, nil, [3][]*rowChunk{{c}}, heatSum{})
|
||||
if !ok {
|
||||
t.Fatal("not named")
|
||||
}
|
||||
sourceDigests.Lock()
|
||||
defer sourceDigests.Unlock()
|
||||
return k, sourceDigestsHashed - was
|
||||
}
|
||||
first, _ := key()
|
||||
if n := dropDigestTurns(); n == 0 {
|
||||
t.Fatal("no serials let go")
|
||||
}
|
||||
sourceDigests.Lock()
|
||||
by, last := sourceDigests.by, sourceDigests.last
|
||||
sourceDigests.Unlock()
|
||||
if by != nil || last != nil {
|
||||
t.Fatalf("kept %d and %d serials when idle", len(by), len(last))
|
||||
}
|
||||
if again, n := key(); n != 0 || again != first {
|
||||
t.Fatalf("after idle: hashed %d, key %s, was %s", n, again, first)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +203,7 @@ func sourceDigest(c *rowChunk, rows *chunkRows) [sha256.Size]byte {
|
||||
}
|
||||
d.by[c.serial] = struct{}{}
|
||||
d.Unlock()
|
||||
derivedUsed() // by and last go when idle (dropDigestTurns)
|
||||
return sum
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user