Commit Graph
2 Commits
Author SHA1 Message Date
yetone 64aaf421ac usage: a packed row holds its time as unix ns and a zone, its tokens in 32 bits (#2278)
A packedRow was 184 bytes; it is 152 now. Its time.Time (24 bytes) is
kept as unix nanoseconds and the *time.Location it was in, read back
with Time(); its six token counts are int32s, not int64s. No call
reads or writes 2^31 tokens; one past it is kept as the most an int32
holds (tokensOf), not wrapped. The archive's encoding is varints and
is unchanged.

Run (mote, through mote-run): go build, go vet, GOOS=linux and
GOOS=windows go vet ./internal/usage, go test ./internal/usage
./internal/usageapi: ok. TestRowTokensAndZoneKept (new) packs a row in
a +05:30 zone at 123ns with 3e9 and -3e9 tokens, and checks time,
zone and the saturated counts after a pack/unpack round trip.
Broken by hand: tokensOf as a plain int32(n) makes it red ("read back
Input -1294967296 ... want 2147483647").

Real history copy on mote (cold start, magpie-ext = v0.1.2296 change):
  cold peak  this 346/342/354 MB (avg 347)  before 373/349/359 (avg 360)
  warm peak  this 273/262 MB               before 297/276
heatmap, overview 0/7/30, stats 0/30 and the request page JSON are
byte-identical to before.
2026-10-31 10:24:23 +08:00
yetone 8974836679 usage: a chunk's rows before the heatmap's cut are counted once, not on every read (#2278)
heatBefore summed the recent chunks' rows before the cut for heatSplit,
pageSplit and effortSplit, unpacking every recent chunk whole each time.
A long-lived session file is recent for weeks (one of the owner's Claude
sessions holds 57k calls), so each recompute of the Usage page while an
agent works unpacked ~200k rows three times. A named chunk's sum is now
kept by its serial and the cut, and dropped after hintsKept reads that
didn't ask for it, as hintsOf keeps a chunk's hints.

Run on mote at this tree:
- go test ./internal/usage ./internal/usageapi: ok
- GOOS=linux|windows|darwin go vet -tags nogui ./internal/usage: ok
- TestHeatBeforeKeptBySerial: sums equal a count of every chunk, a named
  chunk is unpacked once per cut, an unnamed one every time.
  Broken by hand (a kept sum used whatever its cut): red; restored, green.
- A debug build on a copy of the real history logged each call: the
  first reads of a start (concurrent) unpacked 766 non-empty chunks
  (207k rows) each; the next read unpacked none of them.
- Cold start bench, 120s of polls: fp_peak 321MB vs 309MB before, 103 vs
  96 GCs: no change outside noise, since polls answered 304 recompute
  nothing. A bench appending a call every 3s was too noisy on mote
  (load ~20 from other work) to show a difference either way.

Not tried: the GUI suite (no GUI file changed).
2026-10-30 17:42:08 +08:00