perf: incremental cross-window session watch (fix window-open stutter)#107
Merged
Conversation
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
marked this pull request as ready for review
July 18, 2026 19:33
Merged
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (
reattachLiveSessionsbails on a remote window). It's the cross-window state sync:watchSessionsrunsmergeFromDisk(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 viamutateWindowPids) 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
filenamefs.watchalready 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/mergeFromDiskstay 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— cleannpm test— 110/110 (addedmergeRecordupsert/delete cases)fs.watchreports 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