Files
magpie/internal/sessions
yetone f798b4eb7a 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.
2026-11-13 21:34:15 +08:00
..
2026-10-02 08:20:33 +08:00