Repository navigation
perf(tabs): stop PTY layout writes from re-rendering every tab strip (STA-3328) - #12371
brennanb2025 wants to merge 7 commits into
Conversation
The shared 12Hz JS clock wrote el.style.transform on every mounted spinner (41 live = ~490 main-thread style writes/s), keeping style perpetually dirty and delaying keystroke dispatch (measured typing inputDelay p90 363ms; 19ms with the writes stopped). Replace it with a steps(12) CSS transform animation so rotation runs on the compositor; one mount-time animation-delay write preserves the shared-epoch phase sync.
…(STA-3328) Three amplifiers from the terminal-pane React audit, all on the constant orchestration path: - useTabGroupWorkspaceModel subscribed to the global terminalLayoutsByTabId record but only read it inside the activateTerminal callback, so every PTY spawn/attach/reattach re-rendered every mounted worktree's tab strip; now a transient getState read. - The hook returned commands as a per-render literal and TabGroupPanel passed 7 inline arrows, permanently defeating TabBar's React.memo; now memoized. - writePanePtyLayoutBinding rewrote an identical pane->PTY binding on reattach, churning the global record; now bails when unchanged.
|
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: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe workspace model no longer subscribes to terminal layout state. It reads the active terminal leaf transiently and memoizes its commands object. The tab group panel memoizes tab-management handlers before passing them to 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b108ce21-b40b-4af7-9e15-dca259d7e5f8
📒 Files selected for processing (11)
src/renderer/src/assets/main.csssrc/renderer/src/components/AgentStateDot.test.tssrc/renderer/src/components/AgentWorkingSpinner.test.tsxsrc/renderer/src/components/AgentWorkingSpinner.tsxsrc/renderer/src/components/sidebar/StatusIndicator.test.tssrc/renderer/src/components/tab-group/TabGroupPanel.tsxsrc/renderer/src/components/tab-group/useTabGroupWorkspaceModel.render-stability.test.tsxsrc/renderer/src/components/tab-group/useTabGroupWorkspaceModel.tssrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/lib/agent-spinner-clock.test.tssrc/renderer/src/lib/agent-spinner-clock.ts
💤 Files with no reviewable changes (2)
- src/renderer/src/lib/agent-spinner-clock.ts
- src/renderer/src/lib/agent-spinner-clock.test.ts
…sta-3328-tab-group-render-amplifiers
…group-render-amplifiers
|
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. |
|
Closing for now: item 3 is covered by |
Summary
Second installment of the STA-3328 typing-lag work (first: #12359, the spinner clock). This removes the tab-group render amplifiers confirmed by the terminal-pane React audit — the fan-out path that turns every PTY layout write and store notification into fleet-wide tab-strip reconciliation:
useTabGroupWorkspaceModelsubscribed to the globalterminalLayoutsByTabIdrecord but only read it inside theactivateTerminalcallback. Every PTY spawn / attach / reattach in any worktree re-rendered every mounted worktree'sTabGroupPanel(hidden ones included —Terminal.tsxrenders all mounted split surfaces, hiding via CSS). Now a transientuseAppStore.getState()read at call time — the same pattern the callback already used for the runtime-environment lookup — and the record is out of the hook's subscription and the callback's deps.TabBar'sReact.memowas permanently defeated: the hook returnedcommandsas a per-render object literal andTabGroupPanelpassed 7 inline arrow props.commandsis nowuseMemo'd over stable store actions, and the 7 arrows are hoisteduseCallbacks, so the memo can actually bail when nothing tab-related changed.writePanePtyLayoutBindingrewrote identical pane→PTY bindings on reattach, minting fresh global layout state for a no-op. Now bails when the binding is unchanged.Measured context (live prod profiling from the STA-3328 investigation): agent status/title/layout writes are continuous under orchestration, and the 200–488ms render bursts they trigger fan out through exactly this path. The remaining burst source (per-status synchronous store commits) is a separate follow-up; this PR makes each burst cheap instead of fleet-wide.
Render-count delta pinned by the new tests: before, one layout write re-rendered every mounted group's model hook (O(writes × mounted worktrees), with a full
TabBarreconciliation each due to the defeated memo); after, zero re-renders per layout write, andcommandsidentity survives legitimate re-renders.Screenshots
No visual change.
Testing
pnpm lint— oxlint, react-doctor changed-lines gate (exit 0; one pre-existing warning in an untouchedTerminalPaneeffect surfaces from line drift), oxfmt, max-lines ratchet all cleanpnpm typecheck— all three configs passpnpm test— targeted: all 48 tab-group/tab-bar test files (331 tests) + full terminal-pane suite (2,971 tests) pass; full suite left to CIpnpm build— left to CIuseTabGroupWorkspaceModel.render-stability.test.tsxwith a real zustand store and real React rendering (the existing focus-test harness neutersuseMemoand the store, which would make these assertions vacuous). Both tests verified to fail against the pre-fix source (2/2 red on parent): a global layout write must not re-render the hook, andcommandsmust keep identity across store-driven re-renders.AI Review Report
Reviewed for: stale-read hazards from the transient
getState()(none —activateTerminalreads the layout at invocation time, which is fresher than the previously closed-over snapshot; the callback already usedgetState()for the runtime-environment lookup);useMemo/useCallbackdep completeness (all referenced values listed; store actions are stable zustand references;commandsidentity changes only when a constituent callback genuinely changes, e.g.groupTabs); behavior parity of the hoistedTabGroupPanelhandlers (bodies unchanged, same closure values via deps); the binding-guard's skip path (only skips whenexistingBindings[leafId] === ptyId— the written layout would have been structurally identical; the clear path with its active-leaf repair is untouched). Cross-platform: renderer-only React/zustand change, no shortcuts, labels, paths, or shell behavior; SSH reconnect and folder workspaces are the primary beneficiaries (reattach storms were the worst case). The deliberately-skipped sibling fix:setTabLayoutidentity bailout needs a structural comparator onTerminalLayoutSnapshot— not a two-liner, deferred to keep this PR mechanical.Security Audit
No input handling, command execution, path handling, auth, secrets, or IPC changes. Pure render-layer restructuring: one subscription removed, closures memoized, one redundant store write skipped. Test file mocks are scoped to the existing test-mock surface.
Notes
setTabLayoutstructural bailout, split-divider drag off the store (drag-only jank), and the audit's medium-tier findings.TerminalPane.tsx:1647is a pre-existing effect outside this diff (surfaces via line drift); the changed-lines gate passes.