Skip to content

perf: incremental cross-window session watch (fix window-open stutter)#107

Merged
yasithdev merged 1 commit into
mainfrom
session-watch-incremental
Jul 18, 2026
Merged

perf: incremental cross-window session watch (fix window-open stutter)#107
yasithdev merged 1 commit into
mainfrom
session-watch-incremental

Conversation

@yasithdev

Copy link
Copy Markdown
Contributor

Problem

Opening a new remote (cshost) VS Code window briefly hangs the other already-open windows, even for a completely unrelated session.

It isn't SSH — remote windows are observe-only (reattachLiveSessions bails on a remote window). It's the cross-window state sync: watchSessions runs mergeFromDisk(sessions, readAllRecords()) on every record write (extensionStore.ts), re-reading and re-parsing every session file. Every open window runs this watcher, so one window writing a single record (e.g. registering its pid on open via mutateWindowPids) makes every other window synchronously re-read all session files and re-render. Cost scales O(windows × sessions) per write, on the extension-host event loop.

(Note: an async lock was considered and rejected — the per-file lock is rarely contended and isn't the bottleneck; the re-read fan-out is. Making the lock async would be a large async ripple that doesn't touch the actual cost.)

Fix

Use the filename fs.watch already provides and merge only the one record that changed (mergeRecord, undefined = deleted) instead of reading all of them. A short debounce coalesces the 2–3 raw events macOS fires per atomic temp+rename into a single read + render. readAllRecords/mergeFromDisk stay for the initial load and the rare platform that reports no filename.

Per-event work: O(sessions) → O(1). Unrelated windows stop re-reading and (via the existing per-window guard) stop re-rendering on writes that aren't theirs.

Test plan

  • npm run check-types, npm run lint — clean
  • npm test — 110/110 (added mergeRecord upsert/delete cases)
  • End-to-end against the real filesystem + real write path (temp+rename): confirmed fs.watch reports the filename, one write reads only the one changed file (not all 5), and the debounce coalesces macOS's duplicate events to a single read + single render, with the record merged correctly.

🤖 Generated with Claude Code

Cross-window sync watched sessionsDir and, on every record write, ran
mergeFromDisk(readAllRecords()) — re-reading and re-parsing *every* session
file. Every open window (the sidebar and each cshost remote window) runs this
watcher, so one window writing a record (e.g. registering its pid on open) made
every other window synchronously re-read all sessions and re-render, stuttering
unrelated remote windows.

Use the filename fs.watch already reports and merge only that one record
(undefined = deleted). Coalesce the 2-3 raw events macOS fires per atomic
temp+rename into a single read + render. Per-event work drops from O(sessions)
to O(1); readAllRecords/mergeFromDisk stay for the initial load and the rare
platform that reports no filename.
@yasithdev
yasithdev marked this pull request as ready for review July 18, 2026 19:33
@yasithdev
yasithdev merged commit 6411da7 into main Jul 18, 2026
2 checks passed
@yasithdev yasithdev mentioned this pull request Jul 18, 2026
yasithdev added a commit that referenced this pull request Jul 18, 2026
Bump to 0.1.1 and record the incremental cross-window session-watch fix (#107).
@yasithdev
yasithdev deleted the session-watch-incremental branch July 18, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant