Every start parsed the whole of usage.jsonl with json.Unmarshal a line at
a time. On the owner's real history (109 MB) that was 622 MB of the first
18s's 1765 MB allocated, and most of the GC work of a cold start.
The full blocks the log index freezes are now kept in log-v1.bin beside
the sessions cache, with where they end in the log (offset, line count),
the SHA-256 of the log up to there and the hasher's state, first/firstOwn,
the provider keys and hosts seen, and the probe rows before that offset.
A start reads them and parses only the lines after. They stand only
while the log's bytes up to the offset hash the same and the code that
reads them is the same (requestDiskBinary); otherwise the whole log is
parsed as before. The file is written through a temp file and a rename,
at most every 10 minutes and only when it gains blocks.
Run on mote at this tree, rebased on origin/main:
- go test ./internal/usage ./internal/usageapi: ok
- GOOS=linux|windows|darwin go vet -tags nogui ./internal/usage: ok
- TestStartReadsKeptLogBlocks: a second start loads the kept blocks, and
rows, probes, keys, hosts and hash equal a whole parse; a log edited
before the offset is parsed whole.
- Broken by hand: accepting the kept blocks without resumeLogHash turns
TestStartReadsKeptLogBlocks red (hash differs); restored, green.
- Bench on a copy of the real history (~/r2278, 109 MB log), cold start
polled 120s, second start of each binary (caches hit):
v0.1.2184: peaklive 217MB fp_peak 307MB, 156 GCs
this: peaklive 210MB fp_peak 315MB, 98 GCs
readLogSnapshot alloc_space 622MB -> 8.6MB; total 1765MB -> 1095MB.
The first start writes log-v1.bin (7.4 MB).
Not tried: the GUI suite (no GUI file changed); Windows and Linux runs of
the package (vet only).