Repository navigation
perf(diff): stop combined diff sections re-rendering on unrelated settings writes - #36921
Conversation
…tings writes Combined diff viewers and EditorPanel subscribed to the whole settings object, and DiffSectionBody built a fresh Monaco options object each render, so any settings write re-rendered every mounted section and called updateOptions on each. Select only the settings each component reads, let DiffSectionItem read its diff display settings directly, and memoize the DiffEditor options.
…do not re-render editors
|
No actionable comments were generated in the recent review.
|
#37150) Subscribing to the whole settings object re-rendered DiffViewer and rebuilt its options object on every unrelated settings write, which made @monaco-editor/react call updateOptions on the diff editor each time. Select the three diff fields and memoize the options, mirroring the combined diff fix (#36921).
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Upstream changed providers' getDiff arity (stablyai#34779), UpdaterState (stablyai#34104), DiffSectionBody props (stablyai#36577, stablyai#35004), combined diff list props (stablyai#36921), the native chat setting (stablyai#36110), recovery launches waiting for the prompt (stablyai#36210), conflict-resolution props (stablyai#35347) and row-opening params (stablyai#36301). The saved-event case for a write whose views all closed is dropped: upstream no longer notifies then (stablyai#31617), as decided for this rebase.
Summary
In the combined diff view (uncommitted / branch / commit all-diffs, and both PR files combined viewers), every write to any global setting re-rendered every mounted diff section and called Monaco
updateOptionsonce per section, even when the setting had nothing to do with diffs (toggling compact worktree cards, for example). That cost grows with the number of mounted sections.Root cause
Three things combined to cause it:
EditorPanel,CombinedDiffViewer, and both PR combined viewers subscribed to the wholes.settingsobject, so every settings write re-rendered them and every row below them. None of the section components are memoized.settingsobject down as a prop to everyDiffSectionItem, just to readdiffWordWrapanddiffShowWhitespace.DiffSectionBodybuilt theDiffEditoroptionsobject inline.@monaco-editor/reactcallsupdateOptionswhenever that object's identity changes, so every re-render meant oneupdateOptionsper section.Fix
EditorPanelreadsdiffDefaultViewand the markdown review notes flag, andCombinedDiffViewerreads its four diff preferences. This follows the narrow-selector approach thatuseEditorTypography(feat(editor): one typography resolver for every Monaco surface + opt-in weight, line height, ligatures, size and macOS smoothing #36577) uses for the single editor.DiffSectionItemreadsdiffWordWrapanddiffShowWhitespacedirectly. Thesettingsprop is gone fromDiffSectionItemProps,CombinedDiffSectionList,PRFilesCombinedDiffBodyand both PR viewers. The two PR viewers no longer touch the store at all.DiffSectionBodymemoizes the editor options on the inputs that actually change them:isEditable,sideBySide,typography,diffWordWrapanddiffShowWhitespace. Because of this, a section that re-renders for some other reason (comments, height changes) also skipsupdateOptions.useEditorTypography(shared with the single editor, notebooks and excerpts) now selects the resolved typography with a shallow comparison. Before, it selected the raw inputs. The raw inputs include terminal font fallbacks, so changing the terminal font re-rendered every editor even when an explicit editor font made that change inactive. Resolution is cached per surface on the settings object and zoom level, so it runs once per settings write rather than once per mounted editor per store write.Typography still comes from the shared
useEditorTypography('diff')hook. Theme is still the separatethemeprop fromuseMonacoTheme.Visual proof
No visual change: this is a renderer-only render and subscription fix. The control runs below show that font size, inline/side-by-side and word wrap still reach every section.
Perf
What was scanned: the perf-scan workflow on this diff vs
origin/main. It covered the render path from a settings write throughEditorPanel,EditorPanelShell,EditorContent,CombinedDiffViewer,CombinedDiffSectionList,DiffSectionItemandDiffSectionBodyto MonacoupdateOptions.Findings:
DiffViewerstill subscribes to the whole settings object. That is outside this view and left as a possible follow-up.Method:
electron-vitedev build, so React is in development mode), background launch withORCA_BACKGROUND_LAUNCH=1, throwaway per-worktree profiles, driven over CDP with Playwright. Base (origin/main) and branch ran side by side on the same machine.openAllDiffs. 12 sections are mounted in the virtualized viewport.compactWorktreeCardstoggles, 150 ms apart), repeated 3 times.PerformedWorkflags over-count, because a bailed-out subtree keeps the flags from its last render.updateOptionscalls were counted by wrapping every live diff editor.Performance.getMetricsScriptDurationdelta for the whole renderer.DiffSectionItemrendersDiffSectionBodyrendersCombinedDiffViewer/EditorPanelShell/EditorContentrendersupdateOptionscallsterminalFontSizewrites with an explicit editor font (inactive fallback): section renders /updateOptionsThe remaining scripting time is the rest of the app reacting to the setting, mostly the sidebar re-rendering its cards.
Relevant changes still apply to every section:
updateOptionsupdateOptionseditorFontSize+3 (11 mounted editors).view-linesshows the same new font size.monaco-diff-editorhasside-by-side(before: none)diffWordWrapon (13 editors)wordWrap: 'on'On base, each relevant change re-ran
updateOptionsonce per section on every intermediate commit (for example, height re-measures). With memoized options, the branch calls it about once per editor.Merge-risk assessment
Low.
EditorPanel's two settings reads. No IPC, persisted schema or main-process change, so mixed client/server versions are unaffected.EditorPanel'sdiffDefaultViewsync and the combined-diff "session choice beats the global default" logic get the same values as before.pnpm tc:webwould catch any missedsettingsprop caller, and it is clean.Negative user-facing tradeoffs
None known.
Validation
pnpm tc:web,oxlintandoxfmton the changed files.pnpm test:DiffSectionBody.word-wrap-lifecycle, theEditorPanel*suites,EditorPanelShell.headerandcombined-diff-section-index. 38 tests, plus 1 new one.DiffSectionBody.word-wrap-lifecycle.test.tsx): the options object keeps its identity across a re-render that changes no option, and asideBySidechange produces a new object withrenderSideBySide: false. It fails onorigin/main's inline options object.DiffSectionItem/DiffSectionBody; the only change in them is removing the whole-settings subscription and prop.useEditorTypographyand re-measured: the inactive terminal-font row above is now 0 / 0.settingsis undefined and no cache entry exists yet (P2). Fixed. The notebook and Monaco editor suites pass (68 tests).