Skip to content

perf: Use System.Threading.Lock and freeze the ARIA role table - #26589

Open
MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/perf2026-lock-aria
Open

MartinZikmund wants to merge 2 commits into
masterfrom
dev/mazi/perf2026-lock-aria

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.

  • System.Threading.Lock replaces object monitors for the hot, contended private gates in WeakReferencePool and NativeDispatcher.
  • The immutable ARIA control-type role table is a FrozenDictionary.

The original microbenchmarks in #24094 (net10, isolated gates) measured the weak-reference pool gate is 34–58% faster across 1–8 threads, and frozen ARIA lookups are 34% faster.

Validation

  • Compile: Uno.UI.UnitTests (net11.0).
  • Runtime: Given_NativeDispatcher_Concurrency, Given_WeakReferencePool_Concurrency and Given_AriaMapper, 22/22.

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
1M AriaMapper.GetAriaRole lookups 0 → 0 B 0 — 3.67 → 2.14 ms −41.8% ±1.8%
WeakReferencePool rent/return, 4 threads × 50k 2,001,852 → 2,001,896 B +0.00% +0 B 34.93 → 32.41 ms −7.2% (noise) ±4.0%
900 {Binding}s (Name, Address.City, Tags[1]) 16,857,554 → 16,857,554 B 0 — 19.57 → 20.98 ms +7.2% (noise) ±3.1%
200k Tag set/get 0 → 0 B 0 — 20.10 → 22.05 ms +9.7% (noise) ±6.1%

The frozen ARIA role table makes role lookups 42% faster with no allocations. Under 4-thread contention, the weak-reference pool came out 7% faster with Lock, which is within this run's noise. Bindings, which rent from that pool, 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.

@mergify

mergify Bot commented Nov 18, 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

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

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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


Review summary

Verdict: ship. 0 blocking issues, 0 inline findings.

  • System.Threading.Lock: all uses of _gate in NativeDispatcher and WeakReferencePool are plain lock (...) statements. Nothing passes the gate as object, and nothing uses Monitor.Wait or Pulse, so the type change is safe. using System.Threading is present in both files. The projects target the previous and current TFMs (net9.0 and later), and Lock exists from net9.0.
  • FrozenDictionary for AriaMapper.ControlTypeToRoleMap: the field is private, read-only after construction, and keeps the same lookup semantics.
  • Tests: three new test files cover the changes. I found no [Ignore] or Assert.Inconclusive.
  • Not verified: I didn't build or run anything. The PR's reported 22/22 test pass and the benchmark figures are unchecked.
  • Not a defect: the PR is labelled area/automation and carries a 🔄 Refactoring type, though the commit prefix is perf:. Both are fine.
  • The unchecked docs, screenshots and review-two-PRs checklist items look not applicable for an internal change like this.

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_StructureAndProps.png
    • AutomationProperties_AutomationId.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • CalendarView_Theming.png-dark
    • ClipboardTests.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedBackVisualSourceSamplePage.png
    • Basics.png-dark
    • Basics.png
    • ElevatedView_Tester.png-dark
  • skia-windows-screenshots: 260 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • AnimatedVisualsTestbedPage.png-dark
    • Basics.png-dark
    • Basics.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_AutomationId.png

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants