sessions: keeping a file's calls trims the revision windows only when it holds one
keepCalls and keepCallContinuation trimmed every kept window after each keep, under callsMu: a sort of the candidates and a map, twice a file. A request-index build reads ~11.5k session files through four workers, and the files it reads are disk shards that hold no window (weight 0), so each trim changed nothing while the workers queued on callsMu for it. A block and mutex profile of a real-account rebuild showed ~55k contentions on callsMu (about 5 a file), ~3.5 s of lock handoffs and ~4.3 s in pthread_cond_signal. Now keepCalls trims only after keeping a file with a window, and keepCallContinuation only after it adds an entry (its early returns add none). Every window added is still trimmed at once, so the budgets hold as before; a window aging out waits for the next keep that adds one. Run: go test ./internal/sessions ./internal/usage ./internal/gui (ok, on mica), go vet, GOOS=linux and GOOS=windows go vet ./internal/sessions, gofmt -l. Real account on mote (75G sandbox HOME, network blocked): a request-index rebuild forced by a new Anthropic price each run, CPU of the process 30 s after start, alternating: v0.1.4052 21.25 / 17.68 / 15.95 s, this change 14.81 / 14.14 / 13.43 s (mean 18.3 -> 14.1 s). Not tried: a test that counts trims; the change is a cost, and every kept window is still trimmed by the same code.
This commit is contained in:
@@ -216,7 +216,6 @@ func pruneCalls(files []file) {
|
||||
}
|
||||
|
||||
func keepCalls(path string, st *callFile) {
|
||||
defer trimCallRevisions(time.Now())
|
||||
if callRoot == "" {
|
||||
// what is kept is of this root: a Sessions parse that read a
|
||||
// rollout's calls along (callsRide) keeps them before any Requests
|
||||
@@ -250,6 +249,13 @@ func keepCalls(path string, st *callFile) {
|
||||
}
|
||||
callCache[path] = st
|
||||
callOrder = append(callOrder, path)
|
||||
// A file kept with no revision window adds nothing to trim, and a
|
||||
// usage build keeps one for each of the ~11k files a long history
|
||||
// holds: trimming after each, a sort and a map under callsMu, had its
|
||||
// readers waiting on each other for seconds of a build.
|
||||
if st.revisionWeight() > 0 {
|
||||
trimCallRevisions(time.Now())
|
||||
}
|
||||
}
|
||||
|
||||
// wholeCallReaders read an agent's calls from one session file at a time,
|
||||
|
||||
@@ -17,7 +17,6 @@ type callContinuation struct {
|
||||
// keepCallContinuation is called with callsMu held. Published continuations
|
||||
// are immutable; prepareCalls clones them before applying another append.
|
||||
func keepCallContinuation(st *callFile) {
|
||||
defer trimCallRevisions(time.Now())
|
||||
if st.Agent != "codex" && st.Agent != "claude" && st.Agent != "claude-desktop" {
|
||||
return
|
||||
}
|
||||
@@ -54,6 +53,7 @@ func keepCallContinuation(st *callFile) {
|
||||
state.dirty = nil
|
||||
callContinuations[st.Path] = callContinuation{state, len(st.Calls)}
|
||||
callContinuationOrder = append(callContinuationOrder, st.Path)
|
||||
trimCallRevisions(time.Now())
|
||||
}
|
||||
|
||||
func restoreCallContinuation(st *callFile) *callFile {
|
||||
|
||||
Reference in New Issue
Block a user