Skip to content

perf(media): Invert transforms without temporary objects - #26588

Merged
MartinZikmund merged 2 commits into
masterfrom
dev/mazi/perf2026-inversetransform
Nov 20, 2026
Merged

MartinZikmund merged 2 commits into
masterfrom
dev/mazi/perf2026-inversetransform

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: Part of #24093

PR Type:

🔄 Refactoring

What changed? 🚀

Split out of #24094 (originally by @morning4coffe-dev), which now only carries the opt-in XamlOptionalChanges part. This piece is always on, so it gets its own review.

Adds direct inverse point/bounds operations (GeneralTransform.TryTransformInverse / TryTransformBoundsInverse) for places that use the inverse once, so they no longer allocate a temporary MatrixTransform or inverse transform. The public GeneralTransform.Inverse API is unchanged. Callers switched: Slider, ContextRequested, flyout pickers, WASM drag & drop.

Upstream counterpart: 2739fe98.

Behaviour change: for a non-invertible transform, these paths now report false and callers fall back to the input coordinate. Previously they produced Point(NaN, NaN), because Matrix3x2Extensions.Inverse() ignored the result of Matrix3x2.Invert. This matches upstream's E_FAIL contract for CTransform::TransformPoints(..., fInverse: true).

Validation

  • Compile: Uno.UI.UnitTests and SamplesApp (net11.0-desktop).
  • Runtime (Skia desktop): Given_GeneralTransform_Inverse, Given_Slider and Given_ContextRequested, 57/57.

Performance

Headless Skia app with Fluent resources (x64, net10.0, DOTNET_TieredCompilation=0), one process per scenario, 4 interleaved A/B rounds against master. Allocations are UI-thread bytes and exact: a master-vs-master null run drifted 0.00%. A time change is bold only when it is larger than that scenario's null drift and the A/B ranges don't overlap; anything else is marked noise. Background load on the machine made some timings noisy.

Scenario Allocated per iteration Δ alloc Per unit Time per iteration (median) Δ time Null drift
20k ContextRequestedEventArgs.TryGetPosition on a transformed element 24,000,000 → 12,000,000 B −50.00% −600 B 8.87 → 5.93 ms −33.2% (noise) ±1.1%
2,000 Border + child (no templates) 28,781,390 → 28,781,390 B 0 — 8.63 → 11.08 ms +28.4% (noise) ±11.5%
200k Tag set/get 0 → 0 B 0 — 19.45 → 20.67 ms +6.3% (noise) ±6.1%

ContextRequestedEventArgs.TryGetPosition on a transformed element allocates half as much (−600 B per call, the temporary inverse transform) and was about a third faster, though the time ranges overlapped. Untouched paths are unchanged.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01TXMNu1LMuUpziGZWHVDmpX

Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #26588

Verdict: ship. I found no blocking issues, so there are no inline comments. I read the diff and the surrounding code. I did not build or run tests.

Issue count: 0 high, 0 medium, 2 nits.

What I checked

  • Transform.TryTransformInverse and TryTransformBoundsInverse use Matrix3x2.Invert directly and keep the identity fast path. On failure they return false and set the out value to the input, so every converted caller degrades predictably.
  • The GeneralTransform base fallbacks go through InverseCore, so subclasses that don't override them still work. The public Inverse API is unchanged.
  • The ContextRequestedEventArgs failure path returns (0,0). That matches the existing "Transform failed" comment. Before this PR a non-invertible transform returned NaN there, so this is a real change, and the PR description already says so.
  • Each new internal member uses Try… naming and out parameters, and the new code uses tabs and braces. No event Action, no async, and no platform-suffix problems.

Nits (non-blocking)

  1. In Slider.mux.cs, the bool returned by TryTransformInverse is discarded. That is fine because out falls back to the input point. A short note saying "fall back to the input point if not invertible" would make it clear this is deliberate.
  2. In Transform.cs, TryGetInverseMatrix repeats the identity-and-invert logic that Matrix3x2Extensions.Inverse() has. Consider having both share one helper so they can't drift apart.

Cross-cutting

  • The documented NaN to false behaviour change is covered by the new runtime tests (Given_GeneralTransform_Inverse, Given_Slider, Given_ContextRequested). The PR's own validation notes say these passed 57/57.
  • The PR checklist says docs are not updated. That is reasonable for an internal refactor.

@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@github-actions github-actions Bot added the platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform label Nov 18, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247323 found UI Test snapshots differences: skia-linux-screenshots: 426, skia-windows-screenshots: 503

Details
  • skia-linux-screenshots: 426 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppWindowTitleBar Properties.png
    • Basics.png-dark
    • Basics.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_ScreenReader.png-dark
    • AnimatedVisualsTestbedPage.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • CheckBox_DisabledInDisabledListView.png-dark
  • skia-windows-screenshots: 503 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png-dark
    • Accessibility_ScreenReader.png
    • AppWindowTitleBar Properties.png
    • AutomationProperties_StructureAndProps.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png

@MartinZikmund
MartinZikmund merged commit b480dc6 into master Nov 20, 2026
52 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/perf2026-inversetransform branch November 20, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants