Skip to content

perf(serve): event-driven parse reuse — a no-change fetch costs nothing - #960

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

perf(serve): event-driven parse reuse — a no-change fetch costs nothing#960
iamtoruk merged 1 commit into
mainfrom
perf/serve-fs-invalidation

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Answers 'is this the best you could achieve' honestly: it was not. Warm serve still paid the discovery sweep and aggregation per request even when no session data had changed. Now fs.watch over every provider's probeRoots() (the same paths doctor reports) feeds a quiet-since validator: while roots are quiet, parses reuse past the burst window and an output memo answers identical panel queries verbatim. Full safety-rail list in the commit message; the key ones are instant invalidation on any event, a 5-minute self-healing cap for missed events, watcher failures degrading to shorter reuse rather than staleness, and byte-identical one-shot behavior (validator never installed outside serve).

Full suite 2,614 green including new validator reuse tests; builds clean.

The remaining warm-serve cost was the per-request discovery sweep
(stat-ing thousands of session files) plus re-aggregation, even when
nothing on disk had changed. Serve now watches every provider's
probeRoots() via fs.watch (FSEvents-backed recursive watches on macOS)
and injects a quiet-since validator into the parser: while the watched
roots are quiet, a previous parse stays reusable past the burst window,
and an output-level memo returns identical panel queries verbatim - so a
fetch with no data changes skips the sweep AND the aggregation.

Safety rails, in order: a parse is validated-reusable only if the
watchers were armed before it ran; any filesystem event ends reuse
instantly; a 5-minute hard cap self-heals a missed event; a root that
fails to watch just goes uncovered (shorter reuse, never staleness);
outside serve the validator is never installed and behavior is
byte-identical. During an active AI session the session roots fire
constantly, so reuse correctly stays inside the 10s burst window - the
extended reuse serves the idle-browsing case it was built for.

The one watched path inside the cache dir is antigravity's statusline
file specifically, so serve's own cache writes never self-invalidate.
@iamtoruk
iamtoruk merged commit a887233 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