Skip to content

perf: reuse chat tab ownership across unrelated app updates - #26150

Merged
nwparker merged 2 commits into
mainfrom
nwparker/perf-retained-chat-owner-selectors
Oct 8, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/perf-retained-chat-owner-selectors

Conversation

@nwparker

@nwparker nwparker commented Oct 7, 2026 •

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

ELI5

Chats kept open in hidden tabs still listen for app updates. They now reuse their owning workspace instead of searching every workspace again when terminal input, titles or status change.

What Changed

Each chat hook keeps one tab's owner until the relevant tab collection changes. Changing the queried tab creates a fresh selector. File links, launch directories and runtime routing still read the current state on every update.

The resolved-chat runtime selector reuses the same owner factory while preserving its terminal-only lookup. Structured-only chats remain excluded from that runtime lookup; terminal precedence and first-owner collision behavior remain unchanged.

Why

An isolated built Electron fixture with 870 workspace buckets and 20 retained chats showed repeated ownership searches on existing app actions. The original file-link/owner change removed 69,600 bucket scans per terminal-input publication: input went from 3.684 to 0.266 ms, title from 3.551 to 0.259 ms, and status from 3.680 to 0.286 ms. Its no-chat control remained around 0.13 ms.

The runtime follow-up covers a remaining caller after that original change. With 20 mounted resolved chats, one visible and 19 hidden, terminal input fell from 0.692 to 0.286 ms per publication, title from 0.690 to 0.293 ms, and status from 1.025 to 0.565 ms. It removed 17,400 bucket scans and 28,580 row probes per input publication. No-chat controls stayed near 0.19–0.43 ms. The runtime comparison used a temporary copy of the built renderer with only the equivalent memo expression changed; seven measured trials of 100 actual publications followed three warm-up trials.

The runtime follow-up fixture used generated two-turn chat text and provider-session IDs read from its retained chat props, with no PTYs. These measurements do not establish the cause of the reported local Codex typing pause.

Caching only the owner preserves current directory and host routing. The existing terminal-only index has different collision rules and cannot resolve structured chats; a global index or stopping hidden-chat subscriptions would require broader state or lifecycle changes.

Linked Issue

N/A — internal performance audit.

Visual Proof

N/A — rendered content, tab retention and file-link behavior are unchanged. Hidden CDP screenshots confirmed the fixture rendered its generated messages without revealing or focusing a window.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

macOS hidden Electron/CDP production-bundle fixtures. The runtime follow-up passes 31 focused owner, runtime and file-link tests, pnpm tc:web, ordinary lint/format and changed-code quality. Its repeated-scan regression fails against the frozen original with 101 tab-ID reads instead of one. Independent 40,000 runtime-selection comparisons cover collisions, missing/structured-only/empty IDs, 5,333 outer-map replacements and current active, detected, repo, folder, settings and runtime projections.

The original change also passed 40,000 owner and 40,000 file-link-context comparisons, full native-plugin checks and lifecycle/context count regressions. The writer audit covers 68 publication properties in 45 modules plus dynamic writers: ownership changes replace outer tab collections; batches mutate private clones before publication. Linux/Windows remain for CI.

Review

Each selector retains the current collection reference(s) and one owner value for one hook and tab. It accumulates neither queried IDs nor historical collections. Cold imperative helpers remain unchanged. SSH and folder workspace context uses the existing resolver and current runtime/path rules.

Agent skill upstream boundary

  • Not applicable; no upstream skill source or assets copied.

Checklist

  • This PR is small and focused
  • Explained the user-facing before/after, mechanism and alternatives
  • N/A visual proof with reason
  • Self-reviewed correctness, security and performance
  • Cross-platform, SSH/remote and folder workspace impact considered
  • Focused tests, renderer typecheck, lint/format and changed-quality pass; remaining CI checks will run

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 330fc2b5-8d96-47d3-a7e0-99dfb0619816
📥 Commits

Reviewing files that changed from the base of the PR and between 25e0a29 and f70a058.

📒 Files selected for processing (7)
  • src/renderer/src/components/native-chat/NativeChatResolvedView.tsx
  • src/renderer/src/components/native-chat/native-chat-file-link.ts
  • src/renderer/src/components/native-chat/native-chat-owner-selectors.test.tsx
  • src/renderer/src/components/native-chat/native-chat-runtime-owner-selector.test.ts
  • src/renderer/src/components/native-chat/native-chat-runtime-owner.ts
  • src/renderer/src/components/native-chat/use-native-chat-file-link-context.ts
  • src/renderer/src/components/native-chat/use-native-chat-tab-owner.ts

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


📝 Walkthrough

Walkthrough

Native-chat tab-owner lookup now uses a memoized selector that recalculates when tab-map references change. File-link context and runtime environment selection use selectors built on that owner lookup. The file-link and runtime hooks, plus NativeChatResolvedView, pass memoized selectors to the store. Tests cover selector reads, ownership changes, file-link context updates, and runtime projections.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to f70a0

This change reduces redundant ownership scans on unrelated store updates while preserving behavior. No actionable merge-blocking risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: reusing chat tab ownership across unrelated app updates to improve performance.
Description check ✅ Passed The description covers the required ELI5, changes, rationale, issue status, visual proof, testing, review, upstream-boundary, and checklist sections. It explains that visual behavior is unchanged and …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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 67dbd2f into main Oct 8, 2026
30 checks passed
@nwparker
nwparker deleted the nwparker/perf-retained-chat-owner-selectors branch October 8, 2026 07:21
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