Skip to content

perf(win32): Stop raising UIA bounds changes on layout - #24785

Merged
MartinZikmund merged 3 commits into
masterfrom
dev/mazi/win32-uia-bounds
Sep 29, 2026
Merged

MartinZikmund merged 3 commits into
masterfrom
dev/mazi/win32-uia-bounds

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #24784

PR Type:

🐞 Bugfix (performance)

What changed? 🚀

Win32Accessibility.OnSizeOrOffsetChanged raised a UIA BoundingRectangle property-changed event for every element whose visual moved or resized. On most desktops a UIA client is listening (PowerToys, TextInputHost and Chromium browsers all register as one; UiaClientsAreListening() returned true on the test machine). So every scroll frame paid a native UiaRaiseAutomationPropertyChangedEvent call per realized element, and a listener gate alone would not help.

WinUI never raises this event on layout. CUIAWrapper::get_BoundingRectangle serves it on demand, and nothing in dxaml/xcp raises BoundingRectangle changes. This PR drops the per-move raise to match. RaiseAutomaticPropertyChanges on move (IsOffscreen/Name/…) is unchanged, since WinUI does the equivalent from its layout pass.

Measured on the 6.8 backport; the change is identical, and master has the same unconditional raise.

Measurements 📊

ItemsRepeater + UniformGridLayout, 2,837 Fluent Button tiles, 12 × 60 ChangeView steps of 40 px, Skia Win32. UI-thread time from dotnet-trace dotnet-sampled-thread-time (6.8 build, on top of the damage fix):

UI-thread accessibility UI-thread total
6.5.237 (reference) 3 ms 839 ms
before 386 ms 1,756 ms
this PR 148 ms 1,270 ms

What remains is NotifyPropertyChangedEvent from recycled TextBlock text changes, which WinUI raises as well.

PR Checklist ✅

Validation

  • Runtime (Skia Win32, local, 6.8 branch): Given_Win32Accessibility 8/8, including the new When_Element_Moves_BoundingRectangle_Is_Current, which checks that a client pulling bounds after a move gets the new position. The wider Windows_UI_Xaml_Automation run hit the known pre-existing secondary-window teardown crash (WglCurrentContextDisposable.Dispose → GetErrorMessage null); every test before that passed.
  • Compile: Uno.UI.Runtime.Skia.Win32 built without UnoFastDevBuild, so analyzers ran, on master and 6.8.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AzHtsXz33DcziPre7h3b9f

MartinZikmund and others added 2 commits September 28, 2026 14:04
Win32Accessibility raised a BoundingRectangle property-changed event for
every element whose visual moved or resized. UIA clients (PowerToys,
TextInputHost, browsers) are listening on most desktops, so every scroll
frame paid a native UIA call per realized element. WinUI never raises
this event on layout; clients pull BoundingRectangle on demand.

ItemsRepeater grid of 2837 Fluent Buttons, 12 x 60 scroll steps, UI-thread
accessibility time: 386 ms -> 148 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzHtsXz33DcziPre7h3b9f
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 46s —— View job


Review complete ✅

  • Gather context (diff, changed files, AGENTS.md rules)
  • Review Win32Accessibility.cs changes
  • Review new runtime test in Given_Win32Accessibility.cs
  • Post inline findings
  • Summarize review

Verdict: ship — this is a clean, well-scoped performance fix.

Findings by severity: 1 nit (non-blocking), 0 blocking issues.

What I checked:

  • The removed OnSizeOrOffsetChanged raise correctly matches WinUI behavior — BoundingRectangle on Win32 is a computed property (Win32RawElementProvider.BoundingRectangle, Win32RawElementProvider.cs:462) that delegates to the live automation peer/visual on every pull, so dropping the push-side raise carries no staleness risk.
  • RaiseAutomaticPropertyChanges (IsOffscreen/Name/etc.) is untouched, matching the stated intent.
  • The empty override is still required (abstract method on SkiaAccessibilityBase); other platforms (MacOS, WASM) still need push-based updates for their own native APIs, so this isn't a candidate for removing the abstraction.
  • The new runtime test (When_Element_Moves_BoundingRectangle_Is_Current) correctly follows this file's existing helper conventions (ResolveAccessibility/GetOrCreateProvider/GetBoundingRectangle), is scoped with [PlatformCondition(..., SkiaWin32)] + class-level [RunsOnUIThread], and gives a real red→green check for the pull-based bounds behavior (asserts the new position rather than just "no crash").
  • No dangling references to the removed interop call, no unused usings introduced, commit messages follow Conventional Commits.

Cross-cutting note (see inline comment): the base class's scroll re-emission path (SkiaAccessibilityBase.ReemitDescendantPositions, called per ViewChanged) still recursively walks every descendant purely to call the now-no-op OnSizeOrOffsetChanged on Win32. It's strictly cheaper than before (no native call), but it's the same "per realized element, per scroll frame" shape this PR targets, just one layer up — worth a fast-path follow-up, not a blocker for this PR.
· Branch

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBarButtonTest.png
    • AppBarToggleButtonTest.png
    • AppBar_KeyBoard.png
    • ApplicationViewMode.png
    • ApplicationViewSizing.png-dark
    • AppWindowClosing.png
    • AppWindowPresenters.png
    • Arrange_Performance01.png
    • Attributed_text_Supserscript.png-dark
    • Attributed_text_Supserscript.png
    • AutomationProperties_Name.png-dark
    • AutomationProperties_Name.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • 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.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • 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

@unodevops

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 1m 45s —— View job


Review complete ✅

  • Gather context (diff, changed files, AGENTS.md rules)
  • Review Win32Accessibility.cs changes
  • Review SkiaAccessibilityBase.cs changes
  • Review new runtime test in Given_Win32Accessibility.cs
  • Post inline findings
  • Summarize review

Verdict: ship — re-reviewed this PR independently (diff unchanged since the last automated pass); confirms the earlier findings and turns up nothing new.

Findings by severity: 0 new blocking issues, 0 new nits. The one previously-flagged nit (below) still stands as a non-blocking follow-up.

What I verified:

  • OnSizeOrOffsetChanged correctly changed from abstract to a no-op virtual in SkiaAccessibilityBase.cs:81 — MacOS (MacOSAccessibility.cs:407) and WebAssembly (WebAssemblyAccessibility.cs:755) still override it with their push-based implementations, so this isn't a candidate for removing the abstraction, and no other platform is silently broken by the default.
  • The removed Microsoft.UI.Composition using in Win32Accessibility.cs has no other dangling references in that file.
  • The new test When_Element_Moves_BoundingRectangle_Is_Current follows this file's established helper conventions (ResolveAccessibility/GetOrCreateProvider/GetBoundingRectangle, rasterization-scale tolerance) identically to neighboring tests (e.g. When_SelfClipped_Button_ClickablePoint_Uses_Clipped_Center), is correctly scoped to SkiaWin32, and gives a genuine red→green check (asserts the new pulled position, not just absence of a crash).
  • Commit messages follow Conventional Commits; no breaking changes.

Cross-cutting note (already flagged inline in the prior review, still open as a follow-up, not a blocker): SkiaAccessibilityBase.ReemitDescendantPositions (SkiaAccessibilityBase.cs:216) still recursively walks every descendant of a scrolled element on every ViewChanged, purely to invoke the now-no-op OnSizeOrOffsetChanged on Win32 — the same "per realized element, per scroll frame" shape this PR targets, one layer up. Confirmed via RouteVisualOffsetOrSizeChanged and OnScrollSourceChanged — Win32 doesn't opt out of the traversal even though it no longer needs it (MacOS/WASM still do).
· Branch

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • Accessibility_ScreenReader.png-dark
    • AppBar_KeyBoard.png
    • AnimatedIconPage.png-dark
    • AppWindowClosing.png
    • AppBarToggleButtonTest.png
    • AppWindowTitleBar Properties.png
    • ApplicationViewSpanningRectsPage.png
    • Attributed_text_Simple.png
    • AppWindowTitleBar Properties.png-dark
    • AutoBorderStretchwithrightmargin.png
    • Arrange_Performance01.png
    • AutoSizedPathCentered.png-dark
    • Attributed_text_Supserscript.png
    • AutoSuggestBox_BitmapIcon.png
    • AutoBorderStretchwithleftmargin.png
    • BadgeNotificationTests.png-dark
    • AutomationProperties_AutomationId.png
    • BadgeNotificationTests.png
    • AutomationProperties_Name.png-dark
  • 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.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • 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

@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

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.

[Skia/Win32] Accessibility raises a UIA BoundingRectangle event for every moved element on each layout pass

4 participants