Repository navigation
perf(diff): stop the single-file diff viewer re-rendering on unrelated settings writes - #37150
Conversation
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).
|
No actionable comments were generated in the recent review.
|
Summary
The single-file
DiffViewersubscribed to the wholesettingsobject, so any settings write (terminal cursor blink, scrollback, anything) re-rendered it. Each render also rebuilt the inlineoptionsobject, and@monaco-editor/reactcallsdiffEditor.updateOptions(options)whenever that object's identity changes. As a result every unrelated settings write cost one React render plus one MonacoupdateOptionsper open single-file diff.This applies the same fix #36921 used for the combined diff:
diffWordWrap,diffShowWhitespace,diffCollapseUnchangedRegions) instead of the whole object.useMemo, same shape and comment asDiffSectionBody). The memo key includesdiffTypographyfrom the existinguseEditorTypography('diff')hook, which already returns a stable value.useMonacoTheme(). No new selectors or hooks were added.One file changed:
src/renderer/src/components/editor/DiffViewer.tsx.Perf
What was scanned: the perf-scan workflow on the diff vs
origin/main, covering the settings-write path: store write →DiffViewerselector → render → options identity →@monaco-editor/reactupdateOptionseffect → Monaco option diffing for both the original and modified editors.Measurement (dev build,
ORCA_BACKGROUND_LAUNCH=1, CDP on a throwaway profile). I opened a single-file diff of a modifieda.ts, then made 10 unrelatedupdateSettingswrites (alternatingterminalCursorBlinkandterminalScrollbackBytes). Renders were counted fromDiffViewerhook-list identity changes through a React commit hook.updateOptionswas counted by wrapping the mounted diff editor instance.DiffViewerrendersdiffEditor.updateOptionscallsThe base result was reproduced twice; the branch result was measured before and after the base runs.
Control (branch): the relevant settings still reach Monaco:
editorFontSize+3: modified editorfontSizechanged (for example 10 → 13), with 1updateOptionscall.themelight ↔ dark: editor backgroundrgb(255,255,254)↔rgb(30,30,30).diffWordWrap:wordWrapchanged on ↔ off.diffShowWhitespace:ignoreTrimWhitespacechanged false → true.diffCollapseUnchangedRegions:hideUnchangedRegionschanged on ↔ off.Merge-risk assessment
Low. One renderer component changes. The options passed to Monaco are identical to before; only when the object is rebuilt has changed. The memo dependencies cover every non-constant input (
editable,sideBySide,diffTypographyand the three diff settings); everything else is a module constant. There are no schema, IPC or settings changes, so mixed client/server versions are unaffected. Nothing is platform-specific. Folder workspaces and remote runtimes use the same component.Negative user-facing tradeoffs
None known. The rendered diff and option values are unchanged; only redundant renders and
updateOptionscalls are gone.Validation
pnpm tc:web,oxlintandoxfmton the changed file.pnpm test src/renderer/src/components/editor/DiffViewer: passed.gpt-6.1-sol, xhigh) each reviewed the diff and found no valid issues.Builds on #36921 (same pattern for the combined diff).