Skip to content

fix: replace drop-shadow effects with BoxShadow to stop full-window redraws - #2927

Closed
kosmakoff wants to merge 1 commit into
sourcegit-org:developfrom
kosmakoff:fix/drop-shadow-redraw-lag
Closed

kosmakoff wants to merge 1 commit into
sourcegit-org:developfrom
kosmakoff:fix/drop-shadow-redraw-lag

Conversation

@kosmakoff

@kosmakoff kosmakoff commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On my laptop the UI is sluggish: when moving the mouse up and down over the commit history, the row highlight visibly lags behind the cursor. With Avalonia DevTools' dirty rects overlay enabled, the entire window flashes on every mouse move, as if each row highlight triggered a full-window redraw.

I instrumented the app to log every property change and layout pass while hovering the history list. Hovering causes zero layout passes; the only changes are IsPointerOver flags and each row's BackgroundRectangle.Fill (a 1388×26 rect). So SourceGit's own code only invalidates the row it changes, and the full-window redraw comes from the rendering side.

The cause is the custom window frame template in Resources/Styles.axaml:

<Grid Margin="{TemplateBinding Padding}" Effect="drop-shadow(0 0 12 #60000000)">
  <Border x:Name="PART_ContentRoot" ...>
    <!-- the whole window content -->

Avalonia renders a visual that has an Effect, together with all its descendants, into an offscreen layer, then applies the filter to the whole layer. A blur depends on neighbouring pixels, so any change inside the layer dirties the whole effect area. Because this effect wraps the entire window content, every row highlight re-rendered the whole window and re-ran the blur over it. On a 4K panel at 2.25× scale that is a lot of pixels per mouse move. The same mechanism is reported upstream in AvaloniaUI/Avalonia#18358 ("High GPU usage of animation in nested visual tree with static effect"). The reporter's workaround there is also to move the shadow off the parent.

Evidence (gathered on an Avalonia 12 build, where I could toggle each factor independently):

Configuration Whole window flashes on hover Highlight lag
Custom window frame (with drop-shadow effect) yes lags
System native window frame (no effect) yes* much faster; DevTools render time much lower
System native window frame + EGL partial presentation no, only the hovered rows smooth

* The remaining full-window flashing comes from GL swapchains not keeping the previous frame, which forces Avalonia to repaint the whole window anyway. That part is an Avalonia/backend setting and is not changed in this PR. The expensive part is re-running the blur over the whole window, and that is what this PR removes.

Changes

Every drop-shadow Effect becomes a BoxShadow with the same offset, blur and color, placed on the Border that paints the background. A BoxShadow is part of that Border's own drawing, so changes in its children only dirty their own bounds and no blur runs over the content.

  • Custom window frame (Styles.axaml): the main fix. The shadow moved from the Grid wrapping the whole window content to PART_ContentRoot.
  • Tooltips, popups, flyouts, context menus, submenus (Styles.axaml).
  • In-window overlays: repository popup panel, notifications, command palette, search/suggestion lists, scroll-to-top button, auto-fetch notice, merge-conflict error, SSH key generator, statistics tooltip.
  • Hunk Stage/Unstage/Discard bar (TextDiffView.axaml): a StackPanel has no BoxShadow, so a scoped style sets it on each flat button's PART_Border. Stage and Unstage are never visible together, and Discard has an 8px margin, so the per-button shadows don't overlap.
  • Image frames (image diff side-by-side/swipe/blend/difference, revision image preview) and the version badges (About, Self-Update). The swipe/blend/difference views redraw while dragging their sliders, so they also benefit.

No Effect= attributes remain in any .axaml file. No code, dependencies or Avalonia version changes; this is still Avalonia 11.3.22.

Visual note: BoxShadow blur is calculated a little differently from the drop-shadow filter, so shadow edges may look slightly different. If any look too hard or too soft, the third number (blur) can be tuned.

Environment

  • Laptop: Lenovo Y720-15IKB
  • CPU: Intel Core i7-7700HQ (4C/8T, 2.8 GHz)
  • RAM: 32 GB
  • GPU: Intel HD Graphics 630 (renders the desktop, Mesa 26.3.1) + NVIDIA GeForce GTX 1060 Mobile (driver 580.196.07)
  • Display: 3840×2160 @ 60 Hz, 2.25× scale
  • OS: Gentoo Linux, kernel 7.3.6
  • Desktop: KDE Plasma 6.8.3, Wayland session (KWin 6.8.3)
  • .NET SDK: 11.0.100

Related

🤖 Generated with Claude Code

…edraws

An `Effect` renders its visual and all descendants into an offscreen layer
and re-applies the blur filter over the whole layer. Because the custom
window frame put `drop-shadow` on the Grid wrapping the entire window
content, any change inside the window (e.g. hovering a row in the commit
history) invalidated the whole window and re-blurred it every frame,
making row highlight visibly lag behind the mouse. The dirty-rects debug
overlay shows the entire window flashing on every mouse move.

Move every shadow onto the Border that paints the background as a
`BoxShadow` with the same offset, blur and color. A BoxShadow is part of
that Border's own drawing, so changes in its children only dirty their
own bounds. The hunk action bar uses a scoped style to set BoxShadow on
each flat button's PART_Border since a StackPanel has no BoxShadow.

See also AvaloniaUI/Avalonia#18358 for the same effect-on-parent issue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kosmakoff
kosmakoff marked this pull request as ready for review December 4, 2026 19:36
@kosmakoff
kosmakoff marked this pull request as draft December 4, 2026 22:09
@kosmakoff kosmakoff closed this Dec 4, 2026
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