Repository navigation
Cheaper diff scrolling: no forced layouts in the hunk toolbars, no layer per +/- sign - #350291
Merged
Merged
Conversation
Contributor
Screenshot ChangesBase: Changed (12) |
Contributor
There was a problem hiding this comment.
🟡 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>
Alexandru Dima (alexdima)
force-pushed
the
alexd/diff-editor-scroll
branch
from
November 25, 2026 08:06
5885bb3 to
66d4fbc
Compare
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>
Alexandru Dima (alexdima)
force-pushed
the
alexd/diff-editor-scroll
branch
from
November 25, 2026 22:07
66d4fbc to
f80a474
Compare
Alexandru Dima (alexdima)
marked this pull request as ready for review
November 26, 2026 14:12
Alexandru Dima (alexdima)
enabled auto-merge
November 26, 2026 14:12
Henning Dieterichs (hediet)
approved these changes
Nov 26, 2026
Federico Brancasi (federicobrancasi)
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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:
opacity: 0.7made 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, wherecurrentColoris 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: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:
The signs zoomed 12×: before, after, the changed pixels, and the difference 40× brighter:
How to verify
./scripts/test.sh --run src/vs/editor/test/browser/widget/diffEditorWidget.test.ts: the newEditorGuttertest fails without the change (the gutter reads its height on each of 10 scrolls).EditorGutter.render, and fromDiffToolBar.layoutonly when a hunk scrolls into view.mainin a dark, a light and a high-contrast theme, withicon.foregroundcustomized, in an inline diff, and in a notebook diff with a cell selected.🤖 Authored with GitHub Copilot on behalf of Alexandru Dima (@alexdima).