ac4af582301a4e8a29245dbba767eba31334ddf9
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
195d79939e |
dirent: a listing's entry keeps its time as nanoseconds, 40 bytes not 56
Stat.Mod was a time.Time (24 bytes), so an Entry was 56 bytes. The
listings kept for a long history hold up to ~130k entries (keptEntries),
and on the owner's real cache they were the idle heap's 7.7 MB under
dirent.entry. Mod is now unix nanoseconds (int64) with ModTime() for the
three callers that want a time; getattrlistbulk's seconds and
nanoseconds are summed as time.Unix does. An Entry is now 40 bytes.
Run on mote at this head:
- go test ./internal/sessions ./internal/dirent: ok
- GOOS=darwin/linux/windows go vet ./internal/dirent ./internal/sessions:
ok
- gofmt -l: clean
- Broken by hand: a 16-byte pad in Stat makes TestEntrySize red
("an Entry is 56 bytes, want 40").
- Real-account copy (~/r2278/acct), idle heap at 180s: dirent.Stats
7.68 MB -> 4.20 MB (dirent.entry flat 5.68 -> 1.70 MB); Footprint
148 MB.
|
||
|
|
eadeb89c48 |
sessions, dirent: a poll's listings are kept across collections (#2278)
A full history's page polls listed the same folders every few seconds into a fresh slice, map and set each time: the sync.Pools meant to keep them were emptied by the collector, which runs about twice a second at this size, before the next poll took them. - sessions: listingBufs and pathSets are shelves (shelf.go), which keep up to four across collections. listCCFiles makes its slice with the room of the folder's last listing. - dirent: Stats keeps each folder's last listing (Listing.Done(dir)) and the room of the one before, up to 1<<17 entries in all. A name already in the folder's last listing is taken from it, not copied again. 1<<16 kept too little of ~23k session files and their folders: the first bench of this change (budget 1<<16) took dirent.entry from 67-102 to 80-100 MB a minute, no gain. Bench, mote, the real full history (52G Codex in 12,495 files, 13G Claude Code in 10,186), fullallogh.sh, alloc_space between the 50s and 110s heap profiles, MB per minute, before (v0.1.2132 equivalent) -> after: distinctOf 59 -> 22 listCCFiles 42 -> 17 dirent.entry 67-102 -> 55 dirent.nameOf 24 -> 5 Totals swing 400-1200 MB with mote's load (other sessions), so these are per function. Run at this head (rebased on |
||
|
|
7fd65aad56 |
sessions: a Codex listing reuses the last one's names, and dirent its room (#2278)
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 |
||
|
|
d4c6230964 |
sessions: a folder's listing is a sorted slice, and one Codex folder isn't copied
dirent.Stats returned a map per folder. Eight Sessions-page polls on the
owner's real ~/.codex and ~/.claude (copied into a sandbox HOME) spent
~90 MB of their 2.3 GB on those maps alone. It now returns a Listing
sorted by name, found with a binary search (Listing.Get), and
listedRollouts walks it in order instead of sorting the map's keys.
listCodexFiles took the one folder most users have into a fresh slice;
that copy was ~65 MB of the same polls, and the folder's own slice is
now kept.
Run at this head: go test ./internal/dirent ./internal/sessions
./internal/usage ./internal/usageapi ./internal/gui ok; gofmt clean;
GOOS=linux and GOOS=windows go vet -tags nogui on dirent, sessions,
usage and gui clean. stats_test checks the listing is in name order.
A/B on real session files (8 polls of the Sessions trio, 15 s apart,
v0.1.1661 vs this with the next commit): listCodexFiles 129 -> 89 MB,
listedRollouts 87 -> 76 MB, dirent.stats 44 -> 36 MB.
Not tried: the Linux and Windows readdir paths beyond go vet; they
build the same Listing through stats_other.go.
Rebased on
|
||
|
|
7b2a330a56 |
sessions: each session folder is read in one listing on macOS, not a stat() a file
Every 15 s Sessions poll (and every Requests page) lists every agent's session files and stat()s each one: on a real history of ~21.7k files in 462 folders that was ~21.7k lstat()/stat() calls, ~10 µs each on APFS, and the largest part of the poll's CPU. Codex's day folders were also read twice, once by WalkDir and once more for the stat()s. dirent.Stats reads a folder's names, kinds, sizes and modification times with getattrlistbulk, a few calls for the whole folder. statFiles looks each file up in its folder's listing and stat()s alone only a link it follows (ccFiles) or a folder that couldn't be listed so. Codex's rollouts are walked with the listings themselves (listedRollouts), in WalkDir's order, falling back to walkLinked and statFiles when a folder can't be read so. Other systems keep the stat()s as they were. Measured on the real history (~/.claude/projects and ~/.codex sessions, read only): - Stats against os.ReadDir + os.Lstat over all 21,672 entries in 462 folders: 0 mismatched kinds, sizes or times; 43 ms against 257 ms. - `magpie serve` on the real history (sandbox HOME, its projects a link to the real ones), /api/sessions asked back to back with X-Magpie-Had for a 20 s CPU profile: before, 177 ms a poll, process CPU 48.5 s for the run, 17.5 s of samples in statFiles; after, 157 ms, 34.3 s, and no per-file stat() in the profile beyond links. Tests: - TestStatsAsLstat: a file's size and time to the ns, a folder, links to a file, a folder and nothing, a unicode name, and 3000 long names (more than one call's 64 KB answer), each as os.Lstat says. - TestStatFilesAsStat: follow and not, the same files kept with the same sizes and times as os.Stat/os.Lstat; on macOS only the two links are stat()ed alone. Red (7 alone, want 0) with Stats turned off by hand. - TestListedRolloutsAsWalked: nested days, a folder and a link named as rollouts, a .zst, a non-rollout, and a sessions folder that is a link (#2233): the same rollouts, order, sizes and times as walkLinked plus statFiles. Red with the listing's sort taken out by hand. - TestCodexFilesStatInOrder (existing) passes on the new path. Run at this head: - gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on internal/sessions and internal/dirent ok. - go test -tags nogui -count=1 -timeout 45m ./internal/dirent/ ./internal/sessions/ ./internal/usage/ ./internal/gui/: ok (2.4 s, 13.9 s, 15.9 s, 51.1 s). - go test -tags nogui -count=1 -timeout 45m at fe903798f, the packages that import sessions: agent 293s, cli 57s, davsync 73s, gateway 493s, library 192s, otlp 19s, tui 31s, tune 7s, all ok Not tried: Windows and Linux run the stat()s as before, so no change there; an SMB or other network volume on macOS, where getattrlistbulk fails and the per-file path is taken. |