Skip to content

perf(composition): declare damage at present, and make it cheaper to honour - #24821

Merged
MartinZikmund merged 3 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/damage-present-seam
Oct 3, 2026
Merged

MartinZikmund merged 3 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/damage-present-seam

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: #24791

PR Type:

🐞 Bugfix (performance regression)

What changed? 🚀

CompositionTarget.Draw clipped the clear+replay to the damage region by handing the backend a path built from the damaged rectangles. This makes the present the most expensive phase of the frame on master, several times dearer than it is on 6.5.

The present is now told which regions changed when it opens, and each backend decides what to do with them:

  • IDrawingFactory.BeginPresent takes the damaged regions. It is permission to repaint less, not a clip — repainting more is always correct, so a backend may ignore it entirely, or confine the whole session to it. It cannot be expressed as a clip, because a clip is exact: a backend handed several rectangles as one has to honour every edge, and on a GPU that means a coverage mask over everything drawn afterwards.
  • DamageRegion hands back rectangles rather than a geometry, merges overlapping ones, and snaps them to whole device pixels at every scale rather than only at fractional ones. Disjoint, pixel-aligned rectangles are what a backend needs to scissor them.
  • Visual threads the narrowed clip bounds through the render walk instead of recomputing an ancestor chain for every painted visual.
  • WebGpuSwapChainContext declares PreservesContents, so partial repaint reaches WebGPU at all — it renders into one offscreen that it blits whole at present, exactly the retained-target shape Vulkan already declares. WebGpuPresentSession also now queues replays and immediate-mode drawing in order; it previously kept only the last Replay and dropped any earlier one, and applied a clip only to its overlay stream.

Measurements 📊

ItemsRepeater + UniformGridLayout, 2,837 Fluent Button tiles, continuously scrolled. Skia Win32, OpenGL, maximised, 100% scale. Per-frame cost of the two phases, from UNO_LOG_FRAME_PHASES=1 (median of 3 runs):

record / frame draw / frame
6.5.237 2.12 ms 10.05 ms
6.8 + #24788/#24792/#24785 3.43 ms 24.55 ms
master 4.50 ms 31.70 ms
master + this PR 3.40 ms 6.45 ms
master, damage disabled entirely 3.25 ms 8.20 ms

The draw phase is where master regressed, and this brings it below both 6.5 and the damage-disabled control — i.e. damage now pays for itself, where on master it costs about 4x what not having it costs.

Two things this does not fix, and which #24791 should stay open for:

  • record is still ~3.4 ms against 6.5's 2.12 ms. That gap is unrelated to damage — the damage-disabled arm shows the same 3.25 ms — and has not been attributed yet.
  • Layout and Win32 accessibility, which @MartinZikmund measured as the remaining master-vs-6.5 gap in the issue.

Ported to 6.8/6.7 separately: those branches have no IDrawingFactory/IPresentSession seam, so the same intent needs a different shape there.

PR Checklist ✅

Note on the runtime tests box: Given_Visual_Damage covers the region bookkeeping and passes 10/10; the present-side change is covered by the phase measurements above rather than by a new test, since the observable output is unchanged by design.

Depends on #24796 for anything measured on Win32 + OpenGL — without it master freezes the moment the window is maximised.

🤖 Generated with Claude Code

…honour

The present is told which regions changed when it opens, rather than being
handed a clip afterwards, so each backend decides what to do with them.

- IDrawingFactory.BeginPresent takes the damaged regions. Permission to
  repaint less, not a clip: a backend may ignore it, or confine the whole
  session to it.
- DamageRegion hands back rectangles, merges overlapping ones and snaps them
  to whole device pixels at every scale, so a backend can scissor them.
- Visual threads the narrowed clip bounds through the walk instead of
  recomputing an ancestor chain per painted visual.
- WebGpuSwapChainContext declares PreservesContents, so partial repaint
  reaches WebGPU at all, and WebGpuPresentSession queues replays and
  immediate-mode drawing in order rather than keeping only the last.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 236361 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 289, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DisplayInformation.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Focus_FocusVisual_Properties.png-dark
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 289 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationProperties_Name.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AutomationPropertiesExtensions_Role.png
    • Battery.png-dark
    • Battery.png
    • AuthenticationBroker_Demo.png-dark
    • AutomationProperties_AutomationId.png
    • AutomationProperties_Name.png-dark
    • CameraCaptureUISample.png-dark
    • CameraCaptureUISample.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • ContentPresenter_NativeEmbedding_ZIndex.png
    • AuthenticationBroker_Demo.png
    • Buttons.png-dark
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Sep 29, 2026
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 236361 has failed on Uno.UI - CI.

ramezgerges and others added 2 commits September 29, 2026 17:58
An empty try/finally wrapped ContributeDamageOnPaint with its body never
indented, which failed IDE0055 on CI and blocked every downstream build.
A duplicate summary left over from an earlier split went with it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A large virtualized grid that can auto-scroll at a fixed speed, alongside a
ticker and a spinner. Scrolling dirties nearly the whole viewport while the
ticker and spinner change a few hundred pixels, so the sample covers both
ends of partial repaint from one page.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Sep 29, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 236417 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2304, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • ImageIconPage.png-dark
    • Focus_FocusVisual_Properties.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Image_AnimatedWebP.png-dark
    • Image_AnimatedWebP.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 2304 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBarButtonWithIconTest.png
    • ApplicationViewSizing.png
    • AppWindowFeatures.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_Simple.png-dark
    • AutoBorderStretchwithbottommargin.png
    • AutomationPropertiesExtensions_Role.png
    • AutoSuggestBox_BitmapIcon.png
    • AutoSuggestBox_Description.png-dark
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BorderBottomwithmargins.png-dark
    • BorderBottomwithmargins.png
    • BorderImageBrushRelativeTransform.png-dark
    • BorderImageBrushRelativeTransform.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Uno_Web.Http.CookieManagerTests
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation

@MartinZikmund
MartinZikmund merged commit 3bcf00c into unoplatform:master Oct 3, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants