Skip to content

perf(diff): stop the single-file diff viewer re-rendering on unrelated settings writes - #37150

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-diffviewer-settings
Nov 1, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-diffviewer-settings

Conversation

@nwparker

@nwparker nwparker commented Nov 1, 2026 •

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

Summary

The single-file DiffViewer subscribed to the whole settings object, so any settings write (terminal cursor blink, scrollback, anything) re-rendered it. Each render also rebuilt the inline options object, and @monaco-editor/react calls diffEditor.updateOptions(options) whenever that object's identity changes. As a result every unrelated settings write cost one React render plus one Monaco updateOptions per open single-file diff.

This applies the same fix #36921 used for the combined diff:

  • Select only the three settings the viewer reads (diffWordWrap, diffShowWhitespace, diffCollapseUnchangedRegions) instead of the whole object.
  • Memoize the diff editor options (useMemo, same shape and comment as DiffSectionBody). The memo key includes diffTypography from the existing useEditorTypography('diff') hook, which already returns a stable value.
  • Theme keeps using the existing 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 → DiffViewer selector → render → options identity → @monaco-editor/react updateOptions effect → Monaco option diffing for both the original and modified editors.

  • Q1 (unused work): fixed. The broad subscription was the waste. The remaining selectors are three primitive reads per store write.
  • Q2 (ownership): the cost was per mounted single-file diff (Changes mode, editor diff tabs, the external-change compare dialog). It is now zero per unrelated write.
  • Q3–Q6: not applicable. Nothing changes threads, resources, growth or teardown.
  • No findings remain.

Measurement (dev build, ORCA_BACKGROUND_LAUNCH=1, CDP on a throwaway profile). I opened a single-file diff of a modified a.ts, then made 10 unrelated updateSettings writes (alternating terminalCursorBlink and terminalScrollbackBytes). Renders were counted from DiffViewer hook-list identity changes through a React commit hook. updateOptions was counted by wrapping the mounted diff editor instance.

10 unrelated settings writes origin/main this branch
DiffViewer renders 10 0
Monaco diffEditor.updateOptions calls 10 0

The 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 editor fontSize changed (for example 10 → 13), with 1 updateOptions call.
  • theme light ↔ dark: editor background rgb(255,255,254) ↔ rgb(30,30,30).
  • diffWordWrap: wordWrap changed on ↔ off.
  • diffShowWhitespace: ignoreTrimWhitespace changed false → true.
  • diffCollapseUnchangedRegions: hideUnchangedRegions changed 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, diffTypography and 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 updateOptions calls are gone.

Validation

  • pnpm tc:web, oxlint and oxfmt on the changed file.
  • pnpm test src/renderer/src/components/editor/DiffViewer: passed.
  • Real-app CDP measurement and controls as described above.
  • Reviews: an Opus sub-agent and Codex (gpt-6.1-sol, xhigh) each reviewed the diff and found no valid issues.

Builds on #36921 (same pattern for the combined diff).

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).
@coderabbitai

coderabbitai Bot commented Nov 1, 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: 635f491e-c01e-4c4e-a38d-5aa65afff709
Commits

Reviewing files that changed from the base of the PR and between ebe94bc and 438cdd3.

Files selected for processing: 1
  • src/renderer/src/components/editor/DiffViewer.tsx

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

Walkthrough

DiffViewer now selects word wrap, whitespace display, and unchanged-region collapsing separately from the app store. It memoizes the Monaco editor options using those values and other editor inputs, then passes the memoized options to DiffEditor.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 438cd

The optimization preserves DiffViewer behavior and introduces no actionable risk based on the verified source comparison.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
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.
Description check Inconclusive The description follows the template structure and fills in most required sections. The ELI5, What Changed, Why, Testing, Risk, and Validation content is present in substance. The Linked Issue section… 1) Add a Linked Issue: replace the placeholder 'Fixes #' with an actual issue number, or confirm a maintainer exemption applies. 2) Add a Visual Proof section with a BEFORE/AFTER video or screenshots, or write N/A and explain why. The repor…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title names the main change: the single-file diff viewer should stop re-rendering on unrelated settings writes. The raw summary confirms DiffViewer now selects only the three diff settings and mem…
Linked Issues check Passed No active directly linked issues remain. Issue #36921 is closed and supplies historical context only. Therefore, this pull request has no linked-issue coding requirements.
Out of Scope Changes check Passed The change is limited to src/renderer/src/components/editor/DiffViewer.tsx. It narrows the settings selector and memoizes the Monaco options object. These changes match the current pull request inte…
Full details: Title check

Explanation

The title names the main change: the single-file diff viewer should stop re-rendering on unrelated settings writes. The raw summary confirms DiffViewer now selects only the three diff settings and memoizes the Monaco options object, so the title matches the changeset. It is 86 characters, slightly long, but specific and conventional.

Full details: Out of Scope Changes check

Explanation

The change is limited to src/renderer/src/components/editor/DiffViewer.tsx. It narrows the settings selector and memoizes the Monaco options object. These changes match the current pull request intent. No unrelated changes are reported.

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 1 functions across 1 files.

Resolution

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

Full details: Description check

Explanation

The description follows the template structure and fills in most required sections. The ELI5, What Changed, Why, Testing, Risk, and Validation content is present in substance. The Linked Issue section has no issue number (only a 'Fixes #' placeholder), although the description points to #36921 as historical context. The Visual Proof section has no before/after visuals, and the template requires them for behavior changes; the author gives CDP measurements instead. The Risk section gives a Low level, and the description does not state a revert method. The Testing checklist boxes are not ticked, and the AI Disclosure and Agent skill upstream boundary sections are unaddressed. The Notes and Checklist sections are missing. The content is thorough, but several template items are incomplete.

Resolution

  1. Add a Linked Issue: replace the placeholder 'Fixes #' with an actual issue number, or confirm a maintainer exemption applies. 2) Add a Visual Proof section with a BEFORE/AFTER video or screenshots, or write N/A and explain why. The reported CDP measurements do not replace this for behavior changes. 3) Name the ELI5 explanation in plain language, because the current 'What Changed' and 'Summary' sections use code-level terms. 4) Add a 'Level' value (the description says Low, but the template uses the field for the risk level). 5) State how to back out the change (plain revert, or what a revert would not undo). 6) Tick the testing checkboxes, or state which were done. 7) Complete the Agent skill upstream boundary and AI Disclosure sections, or mark them N/A. 8) Add the Notes and Checklist items, or confirm them.
Finishing Touches
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

@nwparker
nwparker merged commit 61f5b84 into main Nov 1, 2026
41 checks passed
@nwparker
nwparker deleted the nwparker/perf-diffviewer-settings branch November 1, 2026 22:01
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