Each Codex listing (several a minute of the page's polls over a long
history) made every rollout's path and key again, grew a new
dirent.Listing an entry at a time for every day folder, and gave each
rollout name a slice of its own in distinctCodexFiles: ~230 MB of a
minute of polls, from 20k unchanged rollouts.
- listedRollouts keeps each day folder's rollouts as its last listing
found them; a rollout listed before keeps its path and key (made
only from its folder and name) and takes its size and time now.
A folder is kept again only when a rollout came or went.
- dirent.Stats takes its listing from a pool and its callers
(listedRollouts, statFiles) give it back with Done once read; Done
clears it. getattrlistbulk's 64 KB buffer is pooled too.
- distinctCodexFiles keeps a name's first file in a map of ints, and
a slice only for names with more files.
New tests: TestListedRolloutsKeepTheirNames (a grown, a removed and a
new rollout; reused strings) and TestStatsAfterDone.
Run on mote. Written on 7037cd980 (v0.1.2126), rebased on 6db21d869
(no sessions or dirent change between); at the pushed head again:
go test -race ./internal/dirent/ ./internal/sessions/ ok, and the
three vets below clean.
At the tree before the rebase:
- go vet -tags nogui ./internal/sessions/ ./internal/dirent/ for
linux, windows and darwin: clean.
- go test -race ./internal/dirent/ ./internal/sessions/: ok, at this
tree. Before the dirent pool was added: also ./internal/usage/ ok
and ./internal/gui/ ok but TestMainWindowCorners (#3949, known).
- Broken by hand: listedRollouts not reading its last listing turns
TestListedRolloutsKeepTheirNames red ("had its path and key made
again"); Done not clearing turns TestStatsAfterDone red.
- Full-history bench (10 endpoints every 5s, heap profiles at 50s and
110s, alloc_space diff), two rounds each, v0.1.2126 against this:
listCodexFiles 229 / 238 MB -> 72 / 92 MB;
dirent.Stats 115 / 130 MB -> 62 / 72 MB;
distinctCodexFiles 40 / 51 MB -> 7 / 12 MB;
readRequestState 318 / 390 MB -> 225 / 222 MB.
The totals (1186 / 694 against 477 / 960 MB) swing with mote's load
more than the change moves them.
Not changed: dirent's names are still copied for each entry (~30 MB),
and Linux and Windows list without dirent.Stats (walkLinked, statFiles'
lstat), so only the distinctCodexFiles part reaches them.
The copy cache trusted a change time it had seen as proof the file had not
changed. NTFS stamps ChangeTime from Windows' clock tick, not the precise
clock: on the Windows box, 300 ms of back-to-back same-size writes got a
new ChangeTime only every ~0.5 ms (2147 of 2691 writes kept the previous
stamp; diffs 0.5/1.0/1.5 ms). A rewrite in the tick of the comparison kept
the stamp the cache saw, so the cached relation was reused. That, not write
merging, is why TestCodexArchivedSameSizeRewriteInvalidatesDiscovery failed
19 of 300 runs on Windows, alone as well as in the full package.
A comparison is now cached only when both files' change times are more than
a second older than the moment it started (codexStampSettle); a file changed
more recently is compared again next time. A later rewrite then lands in a
later tick and changes the stamp. Change times are compared as times
(Windows FILETIME converted).
TestCodexSameTickRewriteIsNotCached gives every write one change time and a
clock 10 ms into that tick. With the settle rule taken out (cacheable = both
stamps present), it fails: "a rewrite in the tick of the comparison reused
its stale relation". With it, it passes, and the second half checks settled
copies are still compared once, not every time.
TestCodexArchivedDiscoveryCacheAndAppend moves its clock a minute on so the
just-written copies count as settled.
The Windows CI step now runs the Codex copy tests (CodexArchived,
CodexSameTick, CodexPlainTwin), which it had never run.
Run: Windows 11 box (cross-built sessions.test.exe, sandbox USERPROFILE/
APPDATA/TEMP): old binary 19/300 failures of the reported test; new binary
0/1000 for the three Codex copy tests, and the Windows CI regex x5 with
testdata passes. macOS: go test -race ./internal/sessions, -race -count=30 of
the Codex copy tests, go vet (darwin, GOOS=linux, GOOS=windows), gofmt -l.
Not run: Linux with a coarse ctime clock (kernels before 6.13); the rule
covers it the same way.