Commit Graph
7 Commits
Author SHA1 Message Date
yetone 3b261932e1 usage: what is kept of each chunk by its serial is let go after three idle minutes
Message keys, match hints, chunk first times and heat sums are kept by
chunk serial and pruned only by turns, so with no pairing or heatmap
while nobody looked they stayed for the life of the process (~4 MB of
message keys alone in a real history's idle heap). They are now let go
once none was read for three minutes, and read again from the chunk on
the next ask.

Test: TestDerivedLetGoWhenIdle (kept while read, let go when idle, same
answers after).

Run: go test ./internal/usage on mote at this head (ok, 36s) and on
the Linux box; go vet linux, windows, darwin. Broken by hand (the drop
skipped): red, "idle: 3 heat sums and 3 firsts kept". Real-account copy
on mote, 330s idle, both orders: hintsOf's 1.6 MB is gone from the end
heap; footprint moved with run order (+10-15 MB for whichever ran
second), so no footprint gain is claimed. Not tried: an idle after the
Requests page was paged, where message keys are kept.
2026-11-10 16:45:02 +08:00
yetone fc9ce34d86 usage: hashRows reuses its scratch, within sizes its rows exactly
Startup on a copy of the owner's real accounts (mote, GUI, network
blocked, acgui.sh) allocated ~3.5GB, and two usage functions were near
the top of it:

- hashRows built a fresh 32KB byte buffer and shape map for every chunk
  it hashed: 510MB of the startup's allocations. It now takes them from
  a sync.Pool and clears the map before use. The digest is the same
  byte for byte (checked against the old code on the same chunks).
- rowChunk.within appended into a nil slice, growing it step by step
  (292MB flat). It now counts the rows in range first, returns nil when
  there are none, and makes the slice at that size.

Measured, same real-account copy, t9 (main) against t10 (this):
  startup CPU      13.81s -> 9.77s
  allocated (3m)   3483MB -> 2768MB (hashRows 510MB -> gone,
                   within 427MB -> 244MB cumulative)
  footprint        179MB  -> 175MB

Tests: TestHashRowsReusesItsScratch hashes a chunk again after a bigger
one and must get the same digest, and must allocate under 16KB a call
(min of 5 batches, so other goroutines' allocations don't count). Old
heat_disk.go: red at 32768 bytes a chunk; dropping clear(shapes): red.
TestWithinSizesItsRows needs len = cap = 600 (old code: cap 646).

Run on mote at this tree: go test ./internal/usage -count=1 ok, -race
ok, gofmt clean, go vet darwin/linux/windows ok, gui tests ok earlier.
An earlier usage run went red on a test whose name was lost (the log was
cut by tail); four full runs since are green, and the likely cause, the
first byte check counting other goroutines, is what the min-of-5 fixes.
2026-11-09 23:56:13 +08:00
yetone 19594cc1cb usage: a span's trimmed chunk keeps only the strings its rows name
A first start's page, heatmap and Codex effort build pair their history
in 4-day spans, and a session file that reaches past a span is trimmed
to it (within). The trimmed chunk cloned the file's whole Strings
table, whose strings all point into the one decoded block of the file:
every span it reached held the whole file's text. within now copies the
strings its kept rows name into one block of its own, renumbers them
("" stays id 0), and rebuilds Shapes through setTexts.

Run on mote, at 2eac91617 plus this change:
- go vet ./internal/usage; go test -count=1 ./internal/usage: ok.
- Broken by hand (every remapped id set to 0 in the mote copy):
  TestFirstBuildPairsSpans FAIL.
- A cold start on the owner's real history copy (~52 GB of Codex
  rollouts, 448k Claude calls) with the window's polls, two runs each,
  against v0.1.2331's build: heatmap, requests, overview 0/7/30 and
  stats 0/30 answers byte-identical. The most live heap in gctrace
  went from 250/253 MB to 245/241 MB. CPU 3:07/3:22 against 3:13/3:07
  (load 4-14). The footprint peak stayed at 329/334 MB against
  333/336 MB: within noise.

Not done: a 2-day or 1-day span took the most live heap to ~235 MB but
changed the last digit of the requests page's float sums and added GCs,
so the span stays 4 days.
2026-10-31 14:16:20 +08:00
yetone ef8dfaa463 usage: a span pairs a long session's rows within its reach alone (#2278)
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.
2026-10-31 11:00:40 +08:00
yetone a377ffde9e usage: a first build pairs four days of history at a time, not two weeks (#2278)
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.
2026-10-31 10:35:47 +08:00
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 f2eb56c6bb usage: a first start pairs the history a few weeks at a time, not at once (#2278)
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.
2026-10-31 03:13:28 +08:00