Skip to content

perf(renderer): index web session tab reconciliation - #8098

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-15
Aug 15, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/perf-15

Conversation

@nwparker

@nwparker nwparker commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Replace the per-editor-tab linear scan in web-session snapshot reconciliation with a lazily-built map, and swap two includes-in-a-loop scans for Set membership.

  • findExistingEditorUnifiedTab ran Array.find over the worktree's whole unified-tab list for every incoming mirrored editor tab. It is now one map keyed by both accepted keys (host tab id and file id), built once per snapshot.
  • Host group order (buildMirroredHostGroups) and tab-bar order rebuild used Array.includes against arrays that grow as the loop runs. Both now use a Set.
  • The map is built lazily on first lookup, so terminal-only snapshots — the common case — pay only an object allocation.
  • The index lives in its own module rather than growing the already-grandfathered reconciliation file.

Scope reduction (rebase)

This PR originally indexed three things. Two were removed because they are no longer wins:

  • Open-file lookup — already shipped on main as firstOpenFileByIdForWorktree (perf(renderer): scope batched open-file reconciliation by worktree #13748). This PR now uses main's index rather than building a duplicate.
  • Remote browser-page lookup — the index eagerly walked every browser workspace's page list for the worktree on first use, so a worktree with many local browser workspaces but only one mirrored page did more work than main. Reverted to findBrowserWorkspaceForRemotePage.

Net effect: +265/-23 becomes +125/-23, and web-session-tabs-sync.ts is -33 lines.

Rebase correctness fix

Two things had rotted and would have broken main:

  • buildMirroredBrowserTabs merged without a conflict marker into non-compiling code: this branch removed state from its signature, while main added state.layoutByWorktree / state.groupsByWorktree reads to its body. Only tsc caught it. Do not merge this PR with the merge button without a rebase.
  • Both new files imported ../../../shared/types, the barrel deleted by refactor(shared): drop the shared/types barrel and import from the real modules #14447. Corrected to shared/tab-types and (no longer needed) shared/browser-workspace-types.

Performance evidence

The benchmark table from the original revision has been removed rather than restated. It measured all three indexes at 2,000 tabs; two of those indexes are gone, so those figures materially overstate what this PR now does. The remaining change has not been re-benchmarked.

What can be stated without measurement: the editor-tab lookup goes from O(editor tabs in snapshot × unified tabs in worktree) to O(unified tabs) setup plus O(1) per lookup, and the two order-merge scans go from O(n²) to O(n). The practical size of that win is bounded by tabs-per-worktree, not by the 2,000-tab figure the original benchmark used.

ELI5

Restoring remote tabs used to re-read the whole tab list from the top for every single tab, like rereading a phone book for each name. It now builds one small lookup table and checks each tab directly — and only builds that table if the snapshot actually contains editor tabs.

End-user trade-offs / regressions

  • None found. This is renderer-local reconciliation of already-received snapshot state.
  • No RPC params, stream opcodes, or persisted state — nothing a paired client and host exchange, so remote wire compatibility is not engaged.
  • No git commands or filesystem paths, so folder (non-git) workspaces, SSH hosts, Windows/Linux, and the Git 2.25 floor are unaffected.
  • Duplicate legacy IDs still resolve to the former first-match result; covered by a focused test.
  • The map is scoped to one synchronous snapshot application and is collectible afterward, so there is no cache-invalidation surface.

Validation

  • pnpm typecheck — all three tsconfigs (node, cli, web)
  • Targeted Vitest: src/renderer/src/runtime — 78 files, 781 tests passed
  • pnpm check:max-lines-ratchet, pnpm check:reliability-gates
  • Targeted oxlint (incl. react-doctor config) + oxfmt

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3179c36-8391-4f26-9e00-48af222b8908

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7f442 and 5ca0bbab74b71fbf1157fda615c05d7085e58e0c.

📒 Files selected for processing (3)
  • src/renderer/src/runtime/web-session-existing-tab-index.test.ts
  • src/renderer/src/runtime/web-session-existing-tab-index.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/runtime/web-session-existing-tab-index.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/runtime/web-session-existing-tab-index.test.ts

📝 Walkthrough

Walkthrough

Adds a lazy index for existing editor tabs, keyed by file ID and host tab ID. The index ignores browser tabs, preserves first matches, resolves conflicts by unified-tab position, and returns null for missing keys. Web session synchronization reuses this index during mirrored editor-tab construction. Tab-order filtering and tab-bar deduplication now use sets. Vitest tests cover lookup precedence and filtering behavior.

Merge Risk: ⚪ Minimal · up to 5ca0b

This localized renderer change replaces repeated tab-list scans with scoped indexes and Set membership without changing the exchanged state or persisted behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and validation, but it omits required template sections, including Linked Issue, Visual Proof, Testing checkboxes, Checklist, and Author. Use the repository template headings, add the required issue link, mark Visual Proof as N/A with a reason if applicable, and complete testing and checklist fields.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies a renderer performance change that matches the tab reconciliation indexing work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and stripped to the zero-cost core.

Two things had rotted since this was opened:

Also dropped from the original change:

  • The openFiles.find index — already shipped on main as firstOpenFileByIdForWorktree in perf(renderer): scope batched open-file reconciliation by worktree #13748.
  • The browser-page index — it eagerly walked every workspace's page list, so a worktree with many local browser workspaces but one mirrored page did more work than main. Restored findBrowserWorkspaceForRemotePage.

What remains is strictly-better with no trade-off: the per-editor-tab Array.find becomes a lazily-built map (terminal-only snapshots pay nothing), plus two includes-in-a-loop scans become Set lookups. Down from +265/-60 to +125/-23.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Replace the per-editor-tab Array.find over the worktree's unified tabs with a
lazily-built id/fileId map, and swap two O(n^2) includes-in-a-loop scans for
Set membership. The map is only materialized when a snapshot actually carries
a mirrored editor tab, so terminal-only snapshots pay nothing.
@nwparker
nwparker merged commit c4e397b into stablyai:main Aug 15, 2026
45 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#8098)

Replace the per-editor-tab Array.find over the worktree's unified tabs with a
lazily-built id/fileId map, and swap two O(n^2) includes-in-a-loop scans for
Set membership. The map is only materialized when a snapshot actually carries
a mirrored editor tab, so terminal-only snapshots pay nothing.
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