Skip to content

perf: less daemon and window memory, fewer requests - #1065

Merged
dspv merged 12 commits into
masterfrom
perf/quick-wins-2026-11-24
Nov 24, 2026
Merged

dspv merged 12 commits into
masterfrom
perf/quick-wins-2026-11-24

Conversation

@dspv

@dspv dspv commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Performance pass of 2026-11-24: less memory and fewer requests, behaviour unchanged.

Measured on an isolated stand (temp HOME, spare port, fake claude), before → after:

  • SQLite page cache 16 → 4 MiB per connection: daemon footprint 518 → 276 MB.
  • First edit of each handed session kept between status refreshes: 322 queries per refresh → 0 after the first.
  • Unchanged module document lists answered from memory: 62 ms and 12 reads → 11 ms and 0 reads.
  • slim=1 events for the inspector: −38% bytes on hook-driven sessions, up to −70%.
  • Session lists carry an ETag; an unchanged list is a 304 with 0 bytes (was 293 KB).
  • Work board keeps only the event fields it reads: 30.5 → 2.4 MB cached.
  • Live session list follows frames: 47.8 → 4.0 asks/min; redraws 984 → 593/min.
  • Menu-bar popover webview made on first open: app memory 189 → 143 MB at start.
  • Summaries' per-session parts kept across restarts (migration 0093, parts_kept, documented in .ai/03-contracts.md): start-up reads ~255 MB → 0 for those figures; equality with a fresh rebuild tested.

Checked on a read-only copy of a real database. Full go test, lint, tsc, vitest, cargo and docs checks pass locally; the two phone e2e failures also fail on master.

dspv added 12 commits November 24, 2026 18:25
On a stand at the owner's scale (1.18M events, 2.8 GB, four tabs, agents
working) the daemon settled at 518 MB, 366 MB of it SQLite's allocator,
which keeps what start-up filled. At 4 MiB: 276 MB, 100 MB SQLite, every
timed endpoint as fast, CPU 10.2% -> 10.7% of a core.
…freshes

HandoffEffect looked for every handed session's first edit and counted the
calls before it once a minute: about 1 GB of disk reads an hour on the
owner's Mac. A first edit once found is kept, and a session with none yet
is read again only after its newest event moved.
The 0.188.0 ETag reached clients that keep tags; the Ops module's scheduled
scripts start as new processes without one, and module lists were still
~7,100 an hour and 37% of the daemon's disk reads on the owner's Mac. Each
page is kept with the tag it was read at (32 MiB at most) and answered
from memory while the collection is unchanged. Who asks is logged at
debug level, once per client and collection per 10 minutes.
The inspector's read of a session's calls carried every result's body and
threw it away on arrival (cockpit slimToolResult): 531-703 KB per session
on the owner's live sessions. With slim=1 the daemon drops it before the
wire, keeping an error's head and interrupted: 38% smaller on a
hook-driven session on the stand, 70% on a long one.
… 304

The workspace asks the full list once a minute (424 KB on the owner's
Mac) and the live one on every tick. The daemon tags each answer with a
hash of its body; the dashboard sends the last tag itself, gets the kept
array back on a 304 and does not merge it into the sidebar again.
…'s events

The board's per-session cache held the newest 70 events whole, written
files and command output included, for up to 256 sessions: 30.5 MB of
payloads on the stand's database. It now keeps a payload's source and
trigger for the turn reading and the tool inputs without file bodies for
the narration (2.4 MB), with every state read the same, and drops a
session the last read did not list.
The workspace asked for the live list on every live tick, a second apart
while anything worked: 47.8 asks and 669 KB a minute beside four agents.
It now asks when a frame names a session it does not hold (at most once a
second) and every 15 s, hidden too for the tray and the Dock badge; the
session frames keep the held ones current. Session frames are applied
once a second instead of every 300 ms. On the Chromium stand: requests
996 -> 383 KB a minute, React commits 984 -> 593 a minute.
The popover's web view was made hidden as soon as a daemon answered and
kept for the life of the app: a second WebKit content process of 25 MB on
the bench whether the popover was ever opened or not. It is now made on
the first click or peek, with a loading mark on its page until it draws.
With the popover never opened the app's processes went 188.9 -> 143.3 MB
at start and 380.3 -> 332.5 MB with eight tabs (bench snapshot build).

Closing it again five minutes after it hid was built and dropped: the
panel's destroy aborted the app in -[NSView removeFromSuperview], WebKit's
window visibility observer failing to remove a KVO observer after the
panel's class swap.
Every start read all of history again to rebuild the 7d, 30d and
all-time parts. They are now written to parts_kept (migration 0093) with
the events mark they were read at, after each whole read and at most
every 10 minutes after; a start reads only the sessions that moved since
that mark, as between two asks in one run. A row is used only by the
build that wrote it and while younger than the 6-hour rebuild. On a copy
of a 2.4 GB database the parts' start-up reads, about 255 MB, are gone.
TestKeptPartsEqualAFreshRead holds the kept range to a fresh count.
The session list ETag (ed7f1e8) skipped the merge when an answer came
back as the same array. The held list can have moved since from frames
and the window's own actions, and eight AppShell tests caught a session
shown twice. The merge already gives back the held list when nothing
differs, so it now runs on every answer; the 304 still saves the bytes.
…rkspace's

A 304 handed every reader the kept array itself, so a reader that changed
its rows changed the next answer too: e2e phone.spec lost the chat's
controls. getTagged now returns a structuredClone. The counted lists
(sessionsWithTotal: phone Home, browser Home, Now) go back to plain
fetches the browser revalidates by the same ETag. golden.spec's route that
rewrites the list fetches without the page's If-None-Match.
@dspv
dspv merged commit 90d5c38 into master Nov 24, 2026
33 of 35 checks passed
@dspv
dspv deleted the perf/quick-wins-2026-11-24 branch November 24, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant