Skip to content

Cheaper diff scrolling: no forced layouts in the hunk toolbars, no layer per +/- sign - #350291

Merged
Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexd/diff-editor-scroll
Nov 26, 2026
Merged

Alexandru Dima (alexdima) merged 2 commits into
mainfrom
alexd/diff-editor-scroll

Conversation

@alexdima

@alexdima Alexandru Dima (alexdima) commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

fyi Henning Dieterichs (@hediet)


Scrolling a side-by-side diff did work on every frame beyond its two editors. Two small fixes, one commit each:

  • Hunk toolbars. The gutter between the editors read its own height on every scroll event, and each hunk's toolbar read its buttons' height right after the gutter moved it, so every hunk in view forced a layout on every scroll event. The gutter now reads its height when it resizes, and a toolbar measures its buttons once, and again when it's rebuilt or its items change.
  • +/- signs. opacity: 0.7 made the rasterizer draw each sign in the margins through a layer of its own, on every frame that scrolls. Dimming the glyph to 70% of its color on ::before, where currentColor is the sign's own color, draws them the same, within 6/255 in a color channel.

This came up while making diffs scroll quickly with the editorView GPU editor (#336479). Both fixes help the DOM editor too.

Measurements

Scrolling a diff of textModel.ts (113 hunks), one wheel event a frame. The gutter forced 7.07 layouts per frame, and now 0.17: a toolbar measures its buttons when its hunk scrolls into view. Alternating old and new in one instance over 8 rounds, busy time per frame:

editorView GPU editor DOM editor
Hunk toolbars: renderer main thread −0.38 ms (6/8 rounds lower) −0.23 ms (6/8)
+/- signs: GPU process −0.31 ms (8/8) −0.20 ms (7/8)

Screenshot changes

The screenshot check flags 12 diff-editor fixtures. In all of them, only the +/- signs change: every + sign changes the same 36 pixels and every − sign the same 10, by at most 6/255 in a color channel. Nothing else moves or changes color. Before, each sign was drawn into a layer of its own and blended at 70%; now its glyph is drawn straight in a 70% color, which blends slightly differently.

All 12 screenshots, with the changed pixels in magenta:

1-overview

The signs zoomed 12×: before, after, the changed pixels, and the difference 40× brighter:

2-signs-zoomed

How to verify

  • ./scripts/test.sh --run src/vs/editor/test/browser/widget/diffEditorWidget.test.ts: the new EditorGutter test fails without the change (the gutter reads its height on each of 10 scrolls).
  • Record scrolling a diff in DevTools' Performance panel: no forced reflows from EditorGutter.render, and from DiffToolBar.layout only when a hunk scrolls into view.
  • Hunk toolbars sit where they did, also after selecting across a hunk. The +/- signs look as on main in a dark, a light and a high-contrast theme, with icon.foreground customized, in an inline diff, and in a notebook diff with a cell selected.

🤖 Authored with GitHub Copilot on behalf of Alexandru Dima (@alexdima).

Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:03
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: ae408942 Current: 55c54ca6

Changed (12)

sessions/changes/agentsDiffEditor/CompactDiffWithFeedback/Light
Before After
before after
sessions/changes/agentsDiffEditor/CompactDiffWithSubmitOverlay/Light
Before After
before after
editor/multiDiffEditor/loading/IncrementalPending/Light
Before After
before after
editor/multiDiffEditor/loading/IncrementalResolved/Light
Before After
before after
editor/multiDiffEditor/loading/DocumentSwapAfter/Light
Before After
before after
editor/multiDiffEditor/variants/cards/ChatInputChanges/Light
Before After
before after
editor/multiDiffEditor/variants/cards/StickyHorizontalOverflow/Light
Before After
before after
editor/multiDiffEditor/variants/cards/StickyHorizontalOverflowAtTop/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileList/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileListTree/Light
Before After
before after
editor/multiDiffEditor/withFileList/WithFileListOnLeft/Light
Before After
before after
editor/multiDiff/multiDiffEditorScroll/RealWidget/Light
Before After
before after

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A recycled gutter toolbar can retain keyboard focus after being rebound to a different hunk, allowing Enter to revert a change other than the one the user focused.

3 open issues
What changed in this PR

This PR reduces diff-editor scrolling overhead for both DOM and GPU rendering by reusing hunk toolbars and simplifying margin-sign rendering.

Changes:

  • Cache gutter and toolbar heights to avoid repeated layout reads during scrolling.
  • Pool offscreen hunk views and add a regression test for reuse and positioning.
  • Replace +/- sign opacity with equivalent color transparency to reduce rendering layers.
File Description
src/​vs/​editor/​test/​browser/​widget/​diffEditorWidget.test.ts Tests gutter view reuse and visible-item positioning after scrolling.
src/​vs/​editor/​browser/​widget/​diffEditor/​utils/​editorGutter.ts Caches gutter height and pools offscreen item views.
src/​vs/​editor/​browser/​widget/​diffEditor/​style.css Uses translucent glyph colors instead of sign opacity.
src/​vs/​editor/​browser/​widget/​diffEditor/​features/​gutterFeature.ts Caches toolbar height and refreshes it when toolbar contents change.

Review effort: Balanced

The gutter between a side-by-side diff's editors is laid out on every
scroll event. It read its own height there, and each hunk's toolbar read
its buttons' height right after the gutter had moved it, so every hunk in
view forced a layout on every scroll event.

The gutter now reads its height when it resizes. A toolbar measures its
buttons once, and again when it is rebuilt or its items change; a hidden
editor's 0 is measured again once it shows.

Scrolling a diff of textModel.ts (113 hunks), the gutter forced 7.07
layouts per frame, and now 0.17: a toolbar measures its buttons when its
hunk scrolls into view. Alternating old and new in one instance over 8
rounds, the renderer's main thread is busy 0.38 ms less per frame with
the editorView GPU editor and 0.23 ms less with the DOM editor (6/8
rounds lower each).

How to verify:
- ./scripts/test.sh --run src/vs/editor/test/browser/widget/diffEditorWidget.test.ts
  The new EditorGutter test scrolls 10 times. Without the change, the
  gutter reads its height on each scroll.
- Record scrolling a diff in DevTools' Performance panel: no forced
  reflows from EditorGutter.render, and from DiffToolBar.layout only when
  a hunk scrolls into view.

🤖 Authored with GitHub Copilot on behalf of @alexdima.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The color mix can replace the +/- glyphs’ themed color with the inherited foreground, while overriding rules can remove the intended 70% attenuation.

1 open issue
3 resolved since last review

Review effort: Balanced

With opacity: 0.7, the rasterizer drew each +/- sign in a diff's margins
through a layer of its own, on every frame that scrolls. Draw the glyph in
70% of the sign's color instead, on ::before, where currentColor is the
color the sign resolved to, whichever rule set it: the icon color, or the
editor's in a notebook diff's selected row. On the sign itself, currentColor
would be its parent's color, and `.monaco-workbench .codicon`, which loads
later, would override the mix and leave the signs undimmed. High-contrast
themes keep drawing them at 70%: their opacity: 1 never applied over the
!important one.

Changing the shipped rule in place in a running window, the signs draw as
on main, within 2/255 in a channel: in Dark Modern, Light Modern and High
Contrast, with icon.foreground set to red, in an inline diff, and in a
notebook diff's focused, selected row.

Scrolling a diff, alternating both in one instance over 8 rounds, the GPU
process is busy 0.31 ms less per frame with the editorView GPU editor (8/8
rounds lower) and 0.20 ms less with the DOM editor (7/8).

How to verify:
- Compare a diff's +/- signs with main in a dark, a light and a
  high-contrast theme, with "workbench.colorCustomizations":
  {"icon.foreground": "#ff4040"}, in an inline diff, and in a notebook diff
  with a cell selected: they look the same.

🤖 Authored with GitHub Copilot on behalf of @alexdima.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the diff-editor scrolling optimizations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@alexdima
Alexandru Dima (alexdima) marked this pull request as ready for review November 26, 2026 14:12
@alexdima
Alexandru Dima (alexdima) added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 1ee35dc Nov 26, 2026
54 checks passed
@alexdima
Alexandru Dima (alexdima) deleted the alexd/diff-editor-scroll branch November 26, 2026 15:10
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.

4 participants