Commit Graph
3 Commits
Author SHA1 Message Date
yetone f1d0c0bfdd usage: Codex's effort is kept on disk for each period, not one (#2278)
effort-v1.json held one entry. The Sessions list asks Codex's effort
for All and the overview for its own period (30d by default), and the
two wrote over each other, so every start, a warm one too, paired one
of them a few days at a time again (effortCold): ~100 MB of the warm
start's live heap at the moment and seconds of CPU. The file now holds
a list of up to four, the last written first, one per since; a file of
one entry, as earlier releases wrote it, is read as that one, so an
upgrade pairs nothing again.

Run on mote (M5 Pro), at this tree:
- go test -count=1 ./internal/usage/: ok (28.6s).
- GOOS=linux and GOOS=windows go vet ./internal/usage/: ok.
- Broken by hand: effortDiskPeriods = 1 turns
  TestCodexEffortPeriodsKeptApart red ("all started again, paired 6 of
  6"); 4 is green.
- Real start on the 11,925-file fixture (8.5GB .zst + 17GB jsonl),
  `magpie web` warm after a cold start, two runs each:
  before (e4c784177) CPU 10.34s / 10.99s, footprint peak 273 / 271 MB;
  after CPU 7.94s / 9.09s, peak 267 / 268 MB. The heatmap, requests,
  overview (0/7/30 days) and stats (0/30) answers are byte for byte the
  same. Heap profiles of the warm start before showed effortCold under
  the overview route at every sample; after, no effortCold is run. Load
  on mote was 28-37 from other sessions.

Not changed: heat-v1.json still holds one entry; a start asks the
heatmap for one filter only, and no warm-start profile showed it built
again.
2026-10-31 17:29:12 +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
yetone cd5df81ecd usage: Codex's effort before the last days is kept on disk, so a start pairs only the recent chunks (#2278)
After the heatmap's settled days were kept (heat-v1.json, fixed in the
commit before), the cold start's largest part was codexEffortOfIndex:
a pairing of the whole history, every gateway call with its session
row, for the effort column, ~90 MB of a ~310 MB heap at 18 s on the
real history bench.

effortSplit does for it what heatSplit does for the heatmap: the effort
of rows before cut (local midnight two days back) comes from memory
while the settled chunks' serials match (10 min), else from
effort-v1.json under a key built by heatSettledKey (the settled chunks,
the recent chunks' rows before cut, the identities, the code, root and
meta); only the chunks since edge are paired again. When neither
stands, the full pairing is used as before and the part before cut is
kept. Old data: no file yet means one full pairing, as today, then the
file. A write that fails only means the next start pairs again.

Real history (mote ~/r2278/full, heap at 18 s, three starts of this
build): CodexModelEffort 14 MB, effortSplit 3.6 MB on the third start
(v0.1.2156: 91 MB); /api/usage/heatmap at 40 s byte-identical to
v0.1.2156's (md5 7e458920...) on all three. The first two starts of a
new binary write the files (the settled chunks differ once between a
fresh build and requests-v1.bin's read), the third reads them.

TestCodexEffortSettledFromDisk: a restart pairs fewer chunks with the
same sums; a changed settled file pairs all with the changed input; a
cold run without the file equals it. Red with effortDiskRead disabled
by hand ("started again, paired 6 of 6").

Run at this tree, on d05482bab + the commit before (mote): go test
-count=1 ./internal/usage ok (86.1s); rebased onto 70a0c387c (an agent
change) and ran again: ok (16.8s); gofmt -l clean; go vet -tags
nogui ./internal/usage ./internal/gui for linux, windows, darwin ok.

Not done here: queryPageOf, the warm-up's QueryPage(All) page 0, is now
the largest part (111 to 227 MB at 18 s), a full pairing for 50 rows.
2026-10-30 14:47:05 +08:00