1ccacad63281094de8a3372d5a507d38f9969e5c
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9cd4ef6a19 |
sessions: an aliased range is named once per change, not on every 10 s read
While the Sessions page is open, the GUI reads the 7, 30 and all-days
ranges again every 10 s. Those ranges are kept (keptStats), so a read
with nothing changed costs almost nothing, except when a model is
counted under another name (a usage alias, or a shared group's spelled
name). Then aliasStats copied every day's usage and every session's
summary of each range on each read: ~5 MB a read for the owner's real
history, which was then thrown away because nothing had changed.
aliasKept keeps each range's aliased Stats with the kept Stats it came
from and the names (provider.UsageNamesKey). When the kept Stats are the
same slices and the names haven't changed, it returns the same answer.
Kept Stats are never written, and MergeExternalStats copies before it
writes, so the answer can be shared. The memo is dropped with the kept
ranges (forgetKeptStats), so it never outlives them. UsageAliasKeyed
reads settings once for both the alias and its key.
Run: TestAliasedRangeMadeOncePerNames (new) passes. With the memo
skipped it fails at "named again with nothing changed". With the key
and source check removed it fails at "the old names' range given after
the names changed". go test ./internal/sessions ./internal/provider
./internal/gui and GOOS=windows / GOOS=linux -tags nogui vet: ok at
|
||
|
|
53280aa08e |
sessions: the stats caches are let go two minutes after the page stops asking
The Sessions page polls /api/sessions/stats every 15 s. Each range it asked
for kept its Stats, the overview and tag sums, about 15 MB on a 14k-session
history, for as long as magpie ran, with the window closed too. Now a timer
armed on every ask drops them two minutes after the last one (not while a
read is busy), with the sessions package's kept ranges, then returns the
memory to the OS. The parsed files stay, so asking again sums them up
again without reading a file.
Measured on mote with a copy of the real accounts (14k sessions), the
statsIdle delay set to 20 s in a measuring build only:
- footprint after six stats asks: t47 (origin/main) 140 MB, t48 151 MB;
- 45 s later: t47 130 MB, t48 116 MB;
- asking again after the release: days=0 0.34 s (was 0.06 s while kept),
days=30 0.17 s.
Run on mote: go vet ./internal/gui ./internal/sessions; go test
./internal/gui ./internal/sessions ok. TestIdleStatsLetGo is red with
`statsMemo.m = nil` taken out ("2 ranges ... kept; want none").
The timer is off under go test, so other gui tests keep their memos.
Not tried: the GUI page itself; the full suite.
|
||
|
|
8d80f6bc0a |
sessions: the kept stats and listing hold an untitled id once, not a map entry
keptStats and keptList noted every answer Codex's titles gave in a map[id]string, to ask each again before the kept ranges are given out. Nearly every id has no title, and the map held 3.12MB on an 18k-file history. titleAnswers keeps the named ones in a map and the untitled ids in a slice, sorted, without repeats or slack once settled; still() asks each again as before. Both caches use it. Run (mote, real-account copy, idle 180s, network blocked): - statsKept.keptTitle.func4 3.12MB -> under the profile's cut; total inuse 107.40MB -> 104.23MB. - TestStatsKeptBetweenPolls now also names a Codex thread after the ranges were kept and checks the title reaches them. TestTitleAnswersSettled checks repeats and slack go. - Broken by hand (still() skipping untitled ids, settle not compacting): TestListKeptBetweenPolls, TestStatsKeptBetweenPolls and TestTitleAnswersSettled red; green on this code. - go test ./internal/sessions/ ok; go vet darwin, linux, windows ok; gofmt clean. Not tried: the full suite (only internal/sessions reads these caches). |
||
|
|
aef89edf10 |
sessions: a listing over unchanged files is the one made last
The Sessions page lists every session every 15 s. Between two polls the files mostly haven't changed, yet each listing grouped, sorted and assembled all of them again (byKey, the key sort, ccFamily, assemble with subagents and resume commands). listSessions now keeps what it made last (keptList, beside keptStats) and gives a copy of it out when nothing it was made from has changed: - every listed file's path, size, time and parse (keptFileOf, the same check the stats use, factored out as keptStill); - the cache generation and the limit asked for; - the prices, Codex thread names and Claude Desktop names the listing got, asked again; - the command an agy row resumes with (AgyStart), when agy is listed. What a row shows beside those (an agent to carry it to being installed, a Claude Code subagent's meta, a Kimi wire file) is looked at again at most a minute later (listKeptFor). refresh now runs before the grouping, which it never read. Reset forgets the kept listing. Measured with the real ~17k sessions (APFS clones of ~/.codex/sessions and ~/.claude/projects in a sandbox HOME), 30 polls of /api/sessions, /api/sessions/stats and /api/sessions/overview, X-Magpie-Had as the page sends it: - before ( |
||
|
|
536a98316d |
sessions: a poll over unchanged files gets the stats the last one read (#2278)
The Usage page asks for its range every 10 s and the Sessions page for 7, 30 and every day every 15 s. Each read put every session of every range together again, though between two polls the files mostly haven't changed: statsReadAll allocated ~1.1 GB per 80 s of polling, a fifth of all magpie allocated. statsKept keeps each range's Stats (at most 8 ranges) and the native keys, with what they were read from: every listed file's path, key, agent, size, mod time, main/read-only, WSL distro and its parse pointer (a published parse is never written; a changed file gets a new one), today, and the cache generation. It also keeps the answers the read got from the prices, Codex's thread names and Claude Desktop's names, and asks them again before it hands anything out. When any of these differ, everything is read again. The listing and the refresh of changed files still run on every poll. MergeExternalStats wrote into the Stats it was given (a day's usage rows, an append into spare room in Sessions, sorts in place). It now copies whatever it changes, so a kept range is never written. What this doesn't help: while an agent is writing a session, every poll sees a changed file and reads everything again. Reading only the changed sessions is the next change. Run at the pushed head on mote: - GOOS=linux/windows/darwin go vet -tags nogui ./internal/sessions/ ./internal/gui/: ok. - go test -count=1 -timeout 45m ./internal/sessions/ ./internal/gui/ ./internal/usage/: sessions ok, usage ok, gui red only TestMainWindowCorners/macOS_26_SDK (#3949, open, same as main). - New tests: TestStatsKeptBetweenPolls (the same backing array on an unchanged poll; a grown file and a price change are read in), TestStatsKeptNewDay, TestStatsKeptRangesBounded, TestMergeExternalStatsWritesNoInput. TestStatsAllRangesOnePass now forgets the kept ranges before each single read. - Broken by hand, each red: keptFor always missing (TestStatsKeptBetweenPolls, "put together again"); the price check dropped (repriced cost unchanged); MergeExternalStats without its copies (TestMergeExternalStatsWritesNoInput). - Real data (a copy of the owner's history, ~34k sessions), v0.1.1978 against this: /api/sessions/stats?days=0/7/30 and both overviews asked 4 times 12 s apart, each pair byte-identical (1.97 MB for days=0). - A/B, 80 s of GUI polling, v0.1.1978 against this: allocated 5512 to 4480 MB, statsReadAll's share 1108 to 261 MB (the listing); GC 3.90 to 3.42 s, madvise 1.05 to 0.61 s, CPU 28.6 to 25.3%, avg RSS 1061 to 1019 MiB. mote's load was 20-40, so latencies aren't compared. The A/B binary was built before the 8-range bound was added. - Rebased onto |