Skip to content

perf: resident serve process — desktop panel fetches drop from ~7s to milliseconds - #956

Merged
iamtoruk merged 1 commit into
mainfrom
perf/serve-stdio
Aug 10, 2026
Merged

perf: resident serve process — desktop panel fetches drop from ~7s to milliseconds#956
iamtoruk merged 1 commit into
mainfrom
perf/serve-stdio

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

The fetching-is-slow complaint, fixed for the release. Full design and measurements in the commit message; highlights:

  • New codeburn serve --stdio: the CLI kept warm as a resident child of the desktop app. Read-only allowlist, strict request serialization, fresh commander program per request (option state is sticky), process.exit converted to a caught error.
  • loadCache memo + serve-only parse burst reuse close the two fixed costs a resident process can actually eliminate (the 100MB+ JSON reload and the per-panel discovery sweep re-run for ranges that differ only by their now-anchor).
  • The app starts the child at startup and routes panel queries through it only once warm; cold start keeps the spawn path (and its progress UI), any failure falls back to a spawn, three child deaths disable serve for the run.
  • Cache sharing unchanged and verified: app, menubar and CLI all resolve the same ~/.cache/codeburn; version-suffixed files with adoption, no pruning or overlap.

Measured warm panel fetches: 5-900ms vs ~7,400ms per spawn (17B-token corpus). One-shot CLI output byte-identical to baseline (diffed); full suite 2,612 green, app suite 468 green, serve protocol + burst + memo covered by new tests.

…illiseconds

Every CLI spawn on a large corpus pays seconds of fixed cost before any
query work: node boot, a 100MB+ session-cache JSON.parse, the discovery +
fingerprint sweep, and serve-time classification. The desktop app spawns
one CLI per panel fetch, so it pays that cost per panel.

codeburn serve --stdio is the same CLI kept warm: the app holds one child,
sends {id, args} per line, and gets the command's stdout back. Three layers
make it fast, each disabled outside serve so one-shot runs stay byte-exact:

- loadCache memo (session-cache.ts): the parsed cache object is reused
  while a stat() shows the file unchanged; saveCache updates it
  write-through. A rewrite by another process still forces a fresh read.
- burst reuse (parser.ts, CODEBURN_PARSE_BURST_MS, serve sets 10s): panel
  bursts anchor their range ends at their own new Date(), so the exact-key
  memo never hits in real traffic; within the window a re-anchored range is
  served by trimming the previous parse instead of re-running discovery.
- fresh commander program per request (main.ts buildProgram factory),
  because commander option state is sticky across parses.

The server allows only the app's read queries (status/overview/models/
sessions/compare/yield/spend/optimize/audit), refuses everything else
(client falls back to a spawn), serializes requests, and converts
process.exit into a caught signal. The app starts the child once at
startup; requests route through it only when warm, cold-start keeps the
spawn path with its progress events, any serve failure falls back to a
spawn, and three child deaths disable serve for the app run.

Measured on a real 17B-token corpus: panel fetches drop from ~7.4s per
spawn to 5-900ms warm (sessions/spend 5ms, status 898ms). One-shot CLI
output verified byte-identical against the pre-branch baseline.
@iamtoruk
iamtoruk merged commit da31f21 into main Aug 10, 2026
5 checks passed
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