Skip to content

perf(wasm): Cheaper record phase for WebGPU and Skia - #26053

Merged
MartinZikmund merged 6 commits into
masterfrom
dev/mazi/wasm-record-perf
Nov 5, 2026
Merged

MartinZikmund merged 6 commits into
masterfrom
dev/mazi/wasm-record-perf

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #26047

PR Type:

✨ Feature (performance)

What changed? 🚀

The WASM record phase was dominated by matrix work that is mostly plain 2D translations:

  • perf(webgpu): WebGpuCommandRecorder.Concat did a full Matrix4x4 multiply for every visual, ~44% of WebGPU recording. A 2D translation now only updates the translation row, with the same result. The save stack is rented from a per-thread pool. It's rented lazily and returned only when empty, because WebGpuPresentSession calls Finish() mid-session and keeps drawing. Before, a fresh stack regrew on every recording.
  • perf: Matrix3x2Extensions.Transform(Rect) (visual culling, every visual, every frame, all backends) now shifts the rect directly for a translation, instead of transforming four corners and taking their bounds. It applies only to rects with non-negative size, and the float rounding matches the corner walk bit for bit.
  • test: fast-path vs full-multiply equivalence, including 3D and perspective parents; the pooled-stack lifecycle; and exact equality of the rect fast path against the corner walk.

Measured on SamplesApp RealWorld_SpotlightMenu, interpreter build, master vs this branch:

master this PR
Pixel Tablet, WebGPU 14.9 fps (record 81 ms) 41.7 fps (record 26 ms)
Pixel Tablet, WebGPU, 3x CPU throttle 5.8 fps 13.6 fps
Pixel Tablet, Skia/WebGL 22.3 fps (record 42 ms) 38.0 fps (record 24 ms)
Pixel Tablet, Skia/WebGL, 3x CPU throttle 9.7 fps 14.3 fps
Desktop Chrome, WebGPU (3 runs) 35–39 fps ~91 fps

Validation: Uno.UI.UnitTests. The new Given_WebGpuCommandRecorder (5) and Given_Matrix3x2Extensions tests pass. The full suite has 12 failures, all in the When_Gregorian_FixedDate* calendar tests, which depend on time zone and locale and are unrelated. The SamplesApp was run on the WebGPU and WebGL backends, on desktop Chrome and on a Pixel Tablet.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA

MartinZikmund and others added 3 commits November 4, 2026 19:09
Recording spent ~44% of its time in Concat: every visual's offset went
through a full Matrix4x4 product, scalar under the WASM interpreter.
A 2D translation now only updates the translation row. The save stack
is also pooled per thread instead of regrowing on every recording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA
Visual culling transforms a rect per visual per frame, mostly by plain
offsets. A translation now shifts the rect directly, with the same
float rounding as the four-corner path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA
@MartinZikmund MartinZikmund added the platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform label Nov 4, 2026
Copilot AI balanced review requested due to automatic review settings November 4, 2026 18:26
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #26053: cheaper record phase for WebGPU and Skia

Verdict: ship. I found no blocking issues. 0 high, 0 medium and 2 nits. This was a review by inspection only. I did not build or run the tests.

What I checked

  • Translate and Concat fast path: Translate(dx, dy) on _m gives the same result as CreateTranslation(dx, dy, 0) * _m, and it updates all four translation-row components. IsTranslation2D requires M43 == 0 and M44 == 1 and checks every other cell. Perspective and 3D parents therefore only take the fast path when the incoming matrix is a pure 2D translation, and the parent's row is handled correctly.
  • Pooled save stack: the stack is rented lazily and returned only when empty. This is safe for WebGpuPresentSession calling Finish() mid-session and then drawing again, because the next Save re-rents. Restore guards with Depth == 0 before it uses _stack. The pool is [ThreadStatic] and capped at 16. A stack rented on one thread and returned on another just lands in that thread's pool. That is harmless.
  • Matrix3x2Extensions.Transform(Rect): the fast path matches the existing corner walk. The identity case matches Transform(double, double), which also returns unrounded doubles for the identity matrix. The translation case adds a (float) coordinate and a float offset, as Vector2.Transform does. The Width >= 0 && Height >= 0 guard excludes Rect.Empty and NaN, whose negative or NaN sizes would reorder the corners.
  • Style: tabs, braces and #nullable follow the surrounding file. The new tests cover the fast path against the full multiply, the stack lifecycle and exact rect equality.

Nits

  • In WebGpuCommandRecorder.cs, IsTranslation2D sits directly above Scale with no blank line. Consider adding one.
  • The == comparisons in IsTranslation2D differ from the full multiply only for NaN or infinity inputs. A 0 * Inf term would give NaN in the multiply but not in the fast path. That is an improvement in practice, but it is a behavioural difference you could note in a comment.

Cross-cutting

  • The PR checklist leaves the docs and screenshot-compare boxes unchecked. The screenshot compare is worth confirming, since the change touches every visual's transform path. No docs look necessary for an internal perf change.
  • The Conventional Commit prefixes are fine.

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 4, 2026

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.

🟡 Changes recommended

The stack pool is bypassed by per-visual and shadow recordings because sessions finish before disposal, causing continued allocations and requiring lifecycle fixes and pooling test coverage.

1 open issue
What changed in this PR

This PR addresses #26047 by reducing matrix-processing and allocation costs during Uno’s WebAssembly recording phase, targeting WebGPU recording and rectangle transforms used across rendering backends.

Changes:

  • Adds translation fast paths for WebGPU matrix composition and rectangle transforms.
  • Introduces lazy, thread-local pooling of WebGPU save stacks.
  • Adds matrix-equivalence and recorder-lifecycle tests.
File Description
src/​Uno.WinRT/​Extensions/​Matrix3x2Extensions.cs Adds a rectangle translation fast path that preserves float rounding.
src/​Uno.UI.UnitTests/​Uno.UI.UnitTests.csproj References WebGPU composition for recorder tests.
src/​Uno.UI.UnitTests/​Extensions/​Given_Matrix3x2Extensions.cs Tests exact equivalence with corner-based rectangle transforms.
src/​Uno.UI.UnitTests/​CompositionTests/​Given_WebGpuCommandRecorder.cs Tests matrix composition and pooled-stack lifecycle behavior.
src/​Uno.UI.Composition.WebGpu/​WebGpuCommandRecorder.cs Optimizes translations and introduces save-stack pooling.

Review effort: Balanced

@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 243709 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AnimatedIconPage.png
    • AppBarToggleButtonTest.png-dark
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSizing.png
    • AppWindowFeatures.png-dark
    • AppWindowPositionAndSize.png
    • AppXamlDefinedResources.png
    • Arrange_Performance01.png
    • Attributed_text_FontSize_Changing.png-dark
    • AutoBorderStretchwithleftmargin.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BackGesture.png-dark
    • BackGesture.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • AnimatedVisualsTestbedPage.png
    • AppBarButtonTest.png-dark
    • AppBarToggleButtonTest.png
    • ApplicationViewSizing.png
    • AppWindowFeatures.png-dark
    • AppWindowPresenters.png-dark
    • AppXamlDefinedResources.png-dark
    • ArcSegment.png
    • Arrange_Performance01.png-dark
    • AuthenticationBroker_Cancel.png-dark
    • AuthenticationBroker_Cancel.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_Landmark.png-dark
    • AutoSizedPathCentered.png
    • AutoSizedTopLeft.png-dark
    • AutoSuggestBox_Description.png-dark
    • AutoSuggestBox_Description.png
    • BackGesture.png-dark
    • BackGesture.png

Copilot AI balanced review requested due to automatic review settings November 5, 2026 08:49
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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


Review of #26053 (after the latest push)

Verdict: ship. 0 high, 0 medium, 0 low. I reviewed by inspection only. I did not build or run the tests.

Copilot's pooling comment is resolved. 5c2cd0e8 now disposes the painting session before recording.Finish() in both of the paths it flagged:

  • The shadow-fallback recording in Visual.skia.cs finishes after the using (childSession) block closes.
  • The per-visual paint path wraps visual.Paint in using (recorderSession) before Finish().

The save stack is therefore empty by the time Finish() calls ReturnStack(), so these paths now reuse pooled stacks. 1d5d177b adds tests that pin this. Mid-session Finish() in WebGpuPresentSession still works, because the stack is only returned when it is empty and is re-rented on the next Save.

Float-equality alerts from github-code-quality. I would dismiss these. The exact == checks in IsTranslation2D are intentional. An epsilon would make the fast path differ from the full multiply, which would break the bit-exact equivalence the tests assert. ba03552b adds a comment that explains this.

Cross-cutting

  • The Screenshots Compare run reports 2458 of 2494 snapshots changed on both skia-linux and skia-windows. That is nearly every sample, which looks like a baseline or infrastructure problem and not a rendering regression from a translation fast path. Still, confirm this against a master run before merging, because the change touches every visual's transform and cull path.
  • The PR checklist still has the screenshot-compare and docs boxes unchecked. No docs look necessary for an internal perf change.

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.

🟢 Approval recommended

No active review issues remain for the translation fast paths and WebGPU save-stack reuse changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@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 243897 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 174

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
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DisplayInformation.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 174 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • Grid_ColSpan_Bottom.png-dark
    • Grid_ColSpan_Bottom.png
    • Grid_DataBound_ColumnRow_Definitions.png-dark
    • Grid_DataBound_ColumnRow_Definitions.png
    • Grid_def_MinMaxValues.png-dark

@MartinZikmund
MartinZikmund merged commit df62fdb into master Nov 5, 2026
57 of 66 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/wasm-record-perf branch November 5, 2026 11:33
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 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.

[WASM] Reduce record-phase cost for WebGPU and Skia

4 participants