At a cold start with the app open, the warm-up's request page and the
GUI's heatmap each read every session file at the same time. Each one
decoded and priced its own chunk of each file. That is twice the CPU,
and the GUI's requests queued behind it. sharedBuild keys a build by
the request state (root and meta, hashed) and by the file's path, size
and time. A query that finds the same file already being made waits
for that build, then takes its own shallow copy, because a query writes
its chunk's serial, use and archive place. The rows and the archive are
shared and only read. If the build panics, the waiter builds its own.
Only QueryPage and the effort index share builds; queryPage's other
callers build as before. blockPricer.share now takes the hashed state
directly.
Measured on mote with synthetic history at #2278's scale (25k Codex
rollouts, 9k Claude sessions, a 115 MB usage.jsonl), with a cold
`magpie web` and 10 GUI endpoints polled every 5 s for 150 s. Built on
v0.1.1903 before the rebase:
- slowest GUI response: 61 s on v0.1.1903, 15.3 s with this change
- footprint peak: 591 MB on v0.1.1903, 609 MB with this change, so no
memory gain; the peak is a transient spread over the page, heatmap,
effort index and session stats (heap profile at 15 s: QueryPage
145 MB, HeatmapOf 87 MB, buildEffort 51 MB, StatsAndNative 43 MB)
TestSharedBuildMakesAFileOnce checks several things:
- a second query waits for the first one's build
- each query gets its own copy, and the copies share one archive
- a change to one copy doesn't show in the other
- the map is empty afterwards
- after a panicked build, the waiter builds its own
With the join broken by hand (the lookup disabled), it failed with "a
file made again while another query was making it".
Run at the pushed tree (rebased onto ca499953e, after b7b817116 and
84a6a2c42 changed request_page.go), on mote:
- go test -race -tags nogui ./internal/usage ./internal/sessions: ok
- go vet -tags nogui ./internal/usage for linux, windows and darwin: ok
Not run: the full suite, and the footprint run at the rebased tree.