A first start, with no sums on disk, paired the whole history a few
days at a time (coldSpans) for the warm-up's page of All (pageCold),
then again for Codex's effort of the same period (effortCold), or the
other way round when the Sessions overview asked first. Both read the
same blocks and name the settled days by the same heatSettledKey, so
whichever runs first now counts both from its one pairing and writes
both files: pageCold counts the effort when its filter is empty and
effort-v1.json lacks it, effortCold counts the cells of the period's
unfiltered page when page-v1.json lacks them.
Run on mote (M5 Pro), at this tree (rebased on 7e0fe83d4):
- go test -count=1 ./internal/usage/: ok (25.5s).
- TestFirstBuildPairsOnceForPageAndEffort asks the page then the
effort, and the effort then the page, each after a cold restart:
the second pairs no span, and both answers equal a build alone.
Broken by hand: pageCold given no effort key, red ("page first:
effort … after N spans"); effortCold counting no cells, red
("effort first: page …").
- Real cold start on the 11,925-file fixture (8.5GB .zst + 17GB
jsonl), `magpie web`, two runs each, alternated:
before (v0.1.2368's tree) CPU 3:11.45 / 3:04.84, footprint peak
332 / 335 MB; after CPU 2:54.02 / 2:57.12, peak 330 / 325 MB. The
heatmap, requests, overview (0/7/30) and stats (0/30) answers are
byte for byte the same. Load on mote 22-28 from other sessions.
Not changed: the footprint's peak barely moves; the two builds ran one
after the other already (coldTurns), so this saves their CPU, not a
peak.
A first build pairs four days at a time, but a chunk was taken whole
into each span it reached. A session file or ledger block written over
weeks was paired in every span: on the owner's history the late spans
paired ~257k rows each, near all of it, ~230k of them from ~180 such
chunks. coldSpans now takes a chunk reaching past a span's
[from-heatReach, to+heatReach) as its rows within that window, and its
rows of no time, as a chunk of its own (rowChunk.within). Rows past the
reach pair with nothing counted in the span. Lazy gateway blocks and
chunks with raw rows are taken as before.
Run (mote, at this head):
- go vet ./internal/usage; GOOS=linux and GOOS=windows go vet
./internal/usage: ok.
- go test -count=1 ./internal/usage ./internal/usageapi: ok.
- TestFirstBuildPairsSpans gains a Codex thread written over 20 days,
each call with its gateway record; spans of 1, 4 and 14 days must
match pairing at once (total 11).
- Broken by hand: within keeping no rows -> TestFirstBuildPairsSpans
red (the long thread's effort 71 vs 141 at once). Not caught: a
window narrowed by heatReach on each side stays green, since the
fixture's call and its record are a second apart.
- Real history (owner's, sandbox HOME copy, cold start, 3 runs each,
against v0.1.2310's change): phys_footprint_peak 313/318/317 MB vs
324/318/325 MB (avg 316 vs 322). CPU 4:15/4:07/4:04 vs
4:10/3:58/3:59 at load ~23 (within noise, maybe +2%). The span log
shows the late spans' rows 256,871 -> 144,691. heatmap, sessions
overview (0/7/30) and stats (0/30) JSON byte-identical in all three
runs; requests equal to 1e-9 (summation order).
Not changed: the peak now sits on the requests page's first build
(~73MB) beside the sessions stats cache (~85MB retained) and Codex
effort (~28MB); those come next.
coldSpan was 14: each span of a first start's pairing held ~1000 to
4700 chunks' matched blocks, priced stubs and Codex pairs at once,
the largest part of the cold-start peak. Four days holds less of it
at the same CPU. The comments that said "a few weeks" say days, and
TestFirstBuildPairsSpans checks 1, 4 and 14 days a span against a
pairing of every chunk.
Run (mote, through mote-run): go build, go vet ./internal/usage,
go test ./internal/usage ./internal/usageapi: ok.
Real history copy on mote, cold starts:
coldSpan 4 peak 319/322/328 MB (avg 323) cpu 3:55/4:23/4:05
coldSpan 14 peak 354/356/342 MB (avg 351) cpu 4:20/4:08/4:05
(an earlier pass: 14 → 353/372, 4 → 332/326, 2 → 325/323 with
cpu 4:26/4:32; 2 days bought little more, so 4.)
heatmap, overview 0/7/30 and stats 0/30 JSON are byte-identical; the
request page differs in 10 floats by summation order only (<1e-9
relative), counts and every other value the same.
Rebased onto b09349d17 (probes.go, search_calls_test.go in usage); go vet
and go test ./internal/usage ./internal/usageapi again there: ok.
With no sums on disk (a first install, or a version that counts rows
otherwise), the page's cells, the heatmap's days and Codex's effort
before the cut were built from one pairing of the whole history. Every
gateway block was priced, every session row's message id went into one
set, and every call into one match map. On the owner's history that
was ~212 MB of the warm-up's 341 MB in use and the cold start's peak.
coldSpans builds them as a day's start advances them (pageAdvance),
14 days at a time. A span pairs the chunks with a row from heatReach
before it to heatReach after. Each chunk's oldest row is kept by its
serial. A gateway block not priced yet is priced by a pricer of the
span alone, and its rows go back to the pool after the span. The
recent days are then paired as on any kept start.
The page's cells come out in another order (by span, then chunk), so
TestSettledCountedAsVersioned now sorts them before it hashes. The
sorted hash is the same for a pairing at once and in spans, so
settledCountVersion stays. Tests that count a pairing of every chunk
use pairAtOnce (coldSpan 0).
Run on mote at the pushed head (rebased on b62fa332f): gofmt -l
clean; go vet ./internal/usage for darwin, linux and windows ok;
go test -count=1 ./internal/usage ok (20.0s); go build . ok.
Broken by hand: TestFirstBuildPairsSpans goes red when a span pairs
only its own days (lo, hi := from, to): the effort differs.
Bench, real history (a year), cold first start, against v0.1.2256,
two rounds each, on mote at load ~22:
no GUI polls: footprint peak 451, 407 MB (2256: 493, 484);
live heap max 318, 289 MB (2256: 367, 362)
GUI polls: footprint peak 483, 410 MB (2256: 534, 532);
live heap max 316, 290 MB (2256: 395, 406)
The heatmap's answers are byte-equal to 2256's. The request page's
differ only in float digits from the summation order (232 floats,
largest relative difference 6.5e-14); every other value is equal.
Not tried: a start on Windows or Linux.