Commit Graph
3 Commits
Author SHA1 Message Date
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
yetone b1f44d099e usage: Codex's effort reuses the pairing the page of its period just made (#3493)
The warm-up builds the Requests page of All and then Codex's model and
effort over All. The page keeps its pairing of the calls (pairMemo, by
chunk serials), but the effort paired every session file's calls again
from nothing, the warm-up's step 3. It now reads requestIndex.pairs[p]
before taking its private copy and pairs through pairRowsMemo, so
unchanged chunks keep their pairing, and it keeps the new pairing for
the next page or effort. Storing a period's pairing is one helper,
keepPairs, that queryPage uses too.

Run at this head (on e1f5f9c16, which origin/main still was):
- TestCodexEffortReusesPagePairing (new): the page pairs once, the
  effort after it pairs 0 times, and equals an effort that pairs on its
  own. Broken by hand (memo -> nil): red, "the effort after the page
  paired again (2 pairings)".
- go test ./internal/usage ./internal/gui ./internal/sessions: ok.
  -race ./internal/usage: ok. go vet -tags nogui GOOS=linux and
  GOOS=windows for usage and gui, gofmt: clean.
- Real data (a copy of the owner's sessions, 421,292 calls), warm-up
  three runs each after one to write the cache file, e1f5f9c16 -> this:
  step 3 0.52-0.58s -> 0.24s; warm-up alloc 1.24-1.29GB -> 1.06GB;
  warm-up 1.80-1.85s -> 1.50s (one 1.77s). Max RSS unchanged (~310-333MB).
- CodexModelEffort(All)'s JSON hash on that data, four runs alternating
  base and this: identical every time (78f93906...).

Not tried: the effort of a period whose page was not built first (it
pairs as before, from nil).
2026-10-25 08:05:33 +08:00
yetone 4982ded8a6 usage: a turned page reuses the last pairing while its chunks are the same
A Requests page paired every Codex session file's calls with the
gateway's again on each query: clone, fold forks, match response ids.
That unpacked every session chunk three times and was about half of a
warm page (#3493). pairRowsMemo names the chunks of a pairing by their
serials (the probe chunk, which has none, by its rows' log offsets and
times) and keeps what the pairing found: the rows left out (skip,
matched), the actors it changed and each chunk's compactions. The next
query over the same chunks and window applies that to fresh clones
instead of pairing again. A changed file gets a new serial, a new
window or period misses, and adopt drops the memos with the parts.

Run at a6399dd49 (= origin/main, fetched):
- TestRequestPairsReusedAcrossPages (new): a gateway call paired with
  its rollout, a fork copying another file's call and a Claude call,
  every page of All/Today/Week at limit 1 and the whole page against
  pageFromLedger. Broken by hand three ways, each red on the memo hit:
  apply without matched ("all page 1: 4 rows, 157 input"), without skip
  ("4 rows, 127 input"), without compactions (page differs).
- Real data, same process (scratch test, not committed), fresh pairRows
  vs the memo applied over a second read: sandbox with the live
  rollouts (symlinked, read only) and a copy of usage.jsonl: All 15607
  chunks, 4801 skip, 1469 matched, 2 actor sets; Today 58 matched; 7d
  1075 matched. Actors, compactions, skip, matched equal, and pages
  equal for 3 filters per period. Without the gateway log: All 15600
  chunks, 4801 skip, all periods equal.
- Timing on that sandbox (load 110-143), page turns after the first:
  v0.1.1449 mean 407 / 460 ms, this change 154 / 145 ms.
- go test -count=1 -timeout 45m ./internal/usage/... ./internal/usageapi/...
  ./internal/sessions/...: usageapi and sessions ok; usage red only on
  TestUsageReadAfterAppendHashesNothingOnAFineClock/whole-second_stamp,
  which is #3511 (taken by another session). At -count=20, load 154,
  it fails 3/20 here and 2/20 at the base 1313b047f; it builds no page.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ok.

Not tried: the GUI against a live gateway; the page reads the same
QueryPage the tests and the real-data run used.
2026-10-25 05:18:41 +08:00