Skip to content

perf(input): Skip re-hit-testing a source that is still valid - #25404

Open
MartinZikmund wants to merge 4 commits into
masterfrom
dev/mazi/hittest-after-leave
Open

MartinZikmund wants to merge 4 commits into
masterfrom
dev/mazi/hittest-after-leave

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #25397

PR Type:

✨ Feature (performance)

What changed? 🚀

When a pointer leave or enter handler removes, collapses or recycles an element, VisualTreeAltered is set. The pointer manager then ran a second full hit test, even when the removed element was neither the original source nor one of its ancestors. The source is now kept while it is still live and hit-test visible. This applies to RaiseLeaveEnter and HitTestIfStale alike, matching WinUI, which dispatches all the events of one input from a single hit test. The VisualTreeAltered doc now states what sets it.

Motivating case: #25389. Its rounded GridView chrome (WinUI's ListViewItemPresenter) removes the hover border on pointer exit, so every pointer move between items hit-tested twice. Hit testing visits the whole tree (#24815), so on a 1,000-tile GridView the synchronous hover cost drops from 24.6 ms to 12.3 ms (3 rounds, Win32 Skia, stacked on #25389).

When the source itself, or an ancestor, is removed or collapsed, a new hit test still runs. When_VisibilityChangesWhileDispatching_Then_RecomputeOriginalSource covers that case.

Validation, runtime (Skia desktop): Given_InputManager, Given_UIElement and Given_ContextRequested pass (628). The new When_LeaveRemovesUnrelatedElement_Then_OriginalSourceNotHitTestedAgain fails without the change (2 hit tests) and passes with it.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC

MartinZikmund and others added 4 commits October 13, 2026 20:13
When a pointer leave or enter handler removed or collapsed an element,
the pointer manager ran a second full hit test. Rounded GridView items
(ListViewItemPresenter chrome) remove their hover border on exit, so
every pointer move between items hit-tested twice. The source is now
kept unless it, or an ancestor, is no longer live and hit-test visible.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
HitTestIfStale, used on the press and cancel paths, now follows the same
rule as RaiseLeaveEnter, and VisualTreeAltered documents what it covers.

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

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 18s —— View job


Review of #25404

Verdict: ship. I found no blocking issues, so I posted no inline comments (0 high, 0 medium, 2 low notes).

I reviewed the diff by inspection. I did not build or run anything.

  • Logic. IsStillHitTarget is a cheap guard (IsActiveInVisualTree plus GetHitTestVisibility() == Visible). It is applied consistently at all four re-hit-test sites: after_leave_with_capture, after_leave, after_enter and HitTestIfStale. If the source or an ancestor is removed or collapsed, it is no longer live or visible, so a fresh hit test still runs. When_VisibilityChangesWhileDispatching_Then_RecomputeOriginalSource covers that case.
  • Root cause. This is a real change to when the hit test runs, not a null guard. The VisualTreeAltered doc comment now states what sets it, which is the invariant the optimization relies on.
  • Tests. The new runtime test counts hit tests on the entered element, and the PR says it fails without the change. The #if !HAS_INPUT_INJECTOR [Ignore] follows the pattern already used in this file.

Low notes (non-blocking):

  1. The assumption that VisualTreeAltered is only set on remove, collapse or recycle matters here. A leave handler that moves or adds an element above the source without setting that flag would now keep a stale source. That would also have been missed before. If other code paths set it, consider a short test for a leave handler that inserts an overlay.
  2. The new test only exercises the after_leave and after_enter path. The capture path (after_leave_with_capture) and HitTestIfStale are changed but not directly covered.

Code style is fine: tabs, braces, and a short comment that explains why.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239293 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • ClipboardTests.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowClosing.png
    • AppWindowFeatures.png
    • AppXamlDefinedResources.png
    • Attributed_text_FontSize_Changing.png-dark
    • AuthenticationBroker_Demo.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutomationProperties_Name.png
    • AutomationProperties_Relations.png-dark
    • AutoSizedPathCentered.png
    • AutoSizedTopLeft.png-dark
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • Basics.png-dark
    • Basics.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund MartinZikmund added the 7.1 PRs only. For issues, use the Release field. label Oct 14, 2026
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
The implicit GridViewItem style is BasedOn DefaultGridViewItemStyle again,
as in WinUI, so default GridView items render through the ListViewItemPresenter
chrome and default to AllowDrop=True. The Fluent GridViewItemExpanded is removed.

Merge after #25403, #25404, #25406, #25409, #25411 and #25413.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 9, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

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

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I compared this with WinUI's PointerInputProcessor::ProcessPointerInput (components/ContentRoot/PointerInputProcessor.cpp). WinUI hit-tests once per input (HitTestWithLightDismissAwareness) and raises enter/leave and then moved/pressed on that same contact element, without re-hit-testing after the handlers. So keeping a source that's still live and hit-test visible brings us closer to WinUI. The VisualTreeAltered cases (remove, collapse, unload, recycle) can only take the source out or hide it, and IsStillHitTarget covers both. One small suggestion inline.

#region Helpers

// The tree is flagged as altered when an element is removed, collapsed or recycled. A source that is still live and
// hit-test visible is kept, as WinUI dispatches all the events of an input from a single hit test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a pointer to the WinUI source here, so nobody "fixes" it back later? PointerInputProcessor::ProcessPointerInput (components/ContentRoot/PointerInputProcessor.cpp) does a single HitTestWithLightDismissAwareness and then raises ProcessPointerEnterLeave and PointerMoved on the same spDOContact, never re-hit-testing after the handlers. Something like // WinUI hit-tests once per input (PointerInputProcessor::ProcessPointerInput).

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

MartinZikmund added a commit that referenced this pull request Nov 13, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 14, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.1 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pointer leave/enter re-hit-tests after unrelated tree changes

4 participants