Repository navigation
perf(renderer): index web session tab reconciliation - #8098
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 5b7f442 and 5ca0bbab74b71fbf1157fda615c05d7085e58e0c. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds 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 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)
✅ Passed checks (3 passed)
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. Comment |
60768da to
dc1ce10
Compare
|
Rebased onto current Two things had rotted since this was opened:
Also dropped from the original change:
What remains is strictly-better with no trade-off: the per-editor-tab |
dc1ce10 to
5ca0bba
Compare
|
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.
5ca0bba to
5aaa016
Compare
…#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.
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.findExistingEditorUnifiedTabranArray.findover 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.buildMirroredHostGroups) and tab-bar order rebuild usedArray.includesagainst arrays that grow as the loop runs. Both now use aSet.Scope reduction (rebase)
This PR originally indexed three things. Two were removed because they are no longer wins:
mainasfirstOpenFileByIdForWorktree(perf(renderer): scope batched open-file reconciliation by worktree #13748). This PR now uses main's index rather than building a duplicate.main. Reverted tofindBrowserWorkspaceForRemotePage.Net effect: +265/-23 becomes +125/-23, and
web-session-tabs-sync.tsis -33 lines.Rebase correctness fix
Two things had rotted and would have broken
main:buildMirroredBrowserTabsmerged without a conflict marker into non-compiling code: this branch removedstatefrom its signature, whilemainaddedstate.layoutByWorktree/state.groupsByWorktreereads to its body. Onlytsccaught it. Do not merge this PR with the merge button without a rebase.../../../shared/types, the barrel deleted by refactor(shared): drop the shared/types barrel and import from the real modules #14447. Corrected toshared/tab-typesand (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
Validation
pnpm typecheck— all three tsconfigs (node, cli, web)src/renderer/src/runtime— 78 files, 781 tests passedpnpm check:max-lines-ratchet,pnpm check:reliability-gatesoxlint(incl. react-doctor config) +oxfmt