Skip to content

perf(editor): reuse model owner keys in closed-tab cleanup - #34691

Merged
nwparker merged 1 commit into
mainfrom
nwparker/menhaden
Oct 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/menhaden

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39

Summary

Workstream 1 of the Oct 27 app-wide lag investigation (build 1.4.243-hourly.202610272224). That profile recorded 499 owner-key calculations in closed-editor cleanup per catalog transition (~498 ms sampled).

attachClosedEditorTabCleanup re-resolved every open tab's model owner route twice (old and new state) on each openFiles change, including a single tab's dirty toggle and catalog/timestamp updates. Its cost grew with open tabs × catalog size.

Owner keys are now cached per OpenFile object and reused until an owner input (the existing EDITOR_BUFFER_ROUTE_INPUT_KEYS + editorBufferIdOf) changes by reference:

  • A change to one tab resolves only that tab.
  • An owner-input change resolves each tab once, not twice.

Ownership semantics are unchanged. The cache invalidates on the same inputs the subscriber's early return already treated as complete, so behavior is the same for local, SSH, runtime, folder workspaces and detach/rejoin. This is a free win: same output, less work.

Proof

Benchmark at the reported census: 251 edit tabs across 171 worktrees, ~1,600 worktree rows, real store and controller. Results compare HEAD with this branch:

Update Owner resolutions (before → after) ms/update (before → after)
One tab dirty toggle 502 → 1 3.45 → 0.05
Catalog timestamp-only update 502 → 251 2.93 → 1.83

A regression test (closed-editor-owner-key-reuse.test.ts) asserts the work count. It fails on HEAD with 40 resolutions for 20 tabs and passes with 1. It also checks that closing a tab still disposes only that tab's model.

Not covered here: removing catalog churn itself (workstream 2, a semantic projection of runtime environments). That fix is larger and needs mixed-version validation.

Testing

  • pnpm check:changed --maxWorkers=2: 28/28 passed
  • Existing closed-editor lifetime, view-state retention and buffer adapter suites pass

Each openFiles change (e.g. a dirty toggle) re-resolved every tab's owner
route twice. Cache owner keys per tab until an owner input changes, so a
single-tab update resolves only that tab.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d96f3ec9-7ede-4025-85ec-1fbdfcc8c0b8
Commits

Reviewing files that changed from the base of the PR and between 6bb0c14 and d08c4ac.

Files selected for processing: 4
  • config/workspace-record-read-baseline.txt
  • src/renderer/src/components/editor/closed-editor-owner-key-reuse.test.ts
  • src/renderer/src/components/editor/closed-editor-tab-controller.ts
  • src/renderer/src/components/editor/editor-model-owner-key-cache.ts
Files with no reviewable changes: 1
  • config/workspace-record-read-baseline.txt

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The change adds a cache for editor model owner keys and uses it in closed-editor tab cleanup. The cache retains keys per open file while editor buffer and route inputs match. The controller uses cached keys to identify closed or replaced edit tabs. Tests check owner-key resolution counts after state changes and verify that closing one tab disposes its model without disposing another tab’s model.

Priority: Normal

Merge Risk: Minimal · up to d08c4

The owner-key reuse change is mergeable after normal checks; no ownership or model-disposal regression was established.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the performance problem, implementation, benchmark results, regression test, and testing performed. However, it omits required template sections, including an actual linked is… Complete the required template sections. Add an actual issue link after “Fixes #”, provide ELI5, What Changed, and Why content, add Visual Proof or state N/A with a reason, and complete the testing, review, notes, and checklist items. Add A…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reusing model owner keys during closed-tab cleanup.
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.
Full details: Description check

Explanation

The description explains the performance problem, implementation, benchmark results, regression test, and testing performed. However, it omits required template sections, including an actual linked issue, ELI5, explicit What Changed and Why sections, Visual Proof or an N/A explanation, and checklist confirmations.

Resolution

Complete the required template sections. Add an actual issue link after “Fixes #”, provide ELI5, What Changed, and Why content, add Visual Proof or state N/A with a reason, and complete the testing, review, notes, and checklist items. Add AI disclosure if the contributor is not a StablyAI team member.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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
nwparker merged commit 68f0c79 into main Oct 28, 2026
42 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