shangyuan0818 on X: on Windows, Usage -> Sessions took 18 to 25 s with
long Claude Code sessions. The cause: a cold read wrote a calls-v15 .gob
shard and a .rev for every Claude session, about 21k files for 12k
sessions, and Windows Defender scans each file as it is closed.
Sessions not changed within the hour are now written into one
calls-v15/*.pack per pass (MPCALLS1 magic, the frames, a gob index of
path/offset/count, length, CRC32, magic). It is written to a temp file
and renamed, and flushed at the end of a pass, at checkpoints, in Saved
and every 32 MB. A session's own shard is read before the pack, so a
session that grows gets its own shard and its lines are appended there
as before. A bad pack means the source is read again. The hourly prune
sweeps packs no session points at. Working sessions keep a shard and a
.rev as before.
Measured on xiaomi-gpu (Windows 11, Defender on), fixture of 12,016
Claude session files, no magpie cache, first /api/sessions reply, the
runs alternating old and new:
origin/main build: 31.67 s, 25.26 s, 20.74 s
this change: 5.92 s, 5.85 s, 5.65 s
restart with the pack written: 1.97 s and 2.16 s; then 0.25 to 0.31 s.
The cache held 1 .pack and 4 .gob.
Tests (call_pack_test.go): TestColdSessionsReadWritesOnePack,
TestPackedCallsServeRequests, TestPackedSessionGrows. With the pack
branch turned off by hand the first fails (.gob:63 .rev:62) and the
second finds 0 packs.
Run at 4ace48feb (this change on origin/main 2ab2f6913):
- gofmt -l: clean.
- go test ./... -timeout 45m -count=1 on mote: 101 packages ok
(internal/sessions 154 s), 3 red, none in code this touches, each
filed: internal/cli TestHealthcheckFindsTheRunningGatewayWithoutMagpieAddr,
TestUpdateRestartsTheGatewayItFindsWithoutMagpieAddr and
TestUpdateFindsAMagpieThatWroteNoRecord (#6223: another session's ssh
forward listened on mote's 127.0.0.1:3425); internal/gateway
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes (#7117) and
TestLaneLimitRoutes (#5150); internal/gui
TestAppReplacesItsOlderGatewayOnceIdle (#6297) and
TestSettingsSaveKeepsWhatItDoesNotSend (#7127, red since f6a538ece).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
vet ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go
build: clean.
- internal/gui/tests/sessions-*.test.cjs (46 files): 322 of 322 in
chromium, 322 of 322 in webkit.
- wsl-run go test ./internal/sessions: ok (25.3 s), at the base before
the rebase.
- win-run go test ./internal/sessions: 4 reds, the same on origin/main
07d19510f and filed as #6071 (TestAgySessions, TestAgyRowOnly,
TestAntigravityAppFolder, TestCCListingKeepsItsNames). go vet clean.
Rebased onto fcbc1a2d0 (three gateway commits, none in
internal/sessions or its doc). At the pushed head: go test
./internal/sessions ok (209 s); go vet of it on darwin, linux (nogui)
and windows clean; go build clean.
Not tried: a real user's profile; the timings use a generated fixture
the size of the report.