Skip to content

perf(dp): Cache DependencyProperty lookups by name - #26585

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

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

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.

  • Lazy DependencyObjectStore maps: master already creates them on first use, so after the rebase this PR only reorders the DEBUG-only owner validation in the store.
  • MetadataAPI's DP reflection cache was a dead Dictionary. It is now a ConcurrentDictionary, because property-path resolution isn't confined to the UI thread. Null results are cached only when the type has no matching member, so a static initializer that hasn't run yet can't poison the entry.
  • The cache is cleared on hot reload (RuntimeTypeMetadataUpdateHandler), and entries from secondary ALCs are evicted through the shared AlcCacheSweep.
  • Owner validation (DEBUG only) evaluates its expensive type checks last.

Validation

  • Compile: Uno.UI.UnitTests (net11.0).
  • Runtime: Given_DependencyObject_LazyState and Given_MetadataAPI_DependencyPropertyCache, 14/14.

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
200k Tag set/get 0 → 0 B 0 — 19.07 → 18.88 ms −1.0% (noise) ±6.1%
2,000 Border + child (no templates) 28,781,390 → 28,781,390 B 0 — 8.27 → 8.19 ms −0.9% (noise) ±11.5%
300 Fluent Buttons, built + laid out 34,689,532 → 34,689,532 B 0 — 88.16 → 88.50 ms +0.4% (noise) ±6.8%
Mixed page: 40 × 7 Fluent controls 90,441,326 → 90,441,326 B 0 — 271.29 → 275.15 ms +1.4% (noise) ±3.1%
900 {Binding}s (Name, Address.City, Tags[1]) 16,857,554 → 16,857,554 B 0 — 17.31 → 17.73 ms +2.4% (noise) ±3.1%
Layout pass over 1,000 elements 1,392 → 1,392 B 0 — 1.45 → 1.69 ms +15.9% (noise) ±0.4%
100k DP lookups by name (MetadataAPI.TryGetDependencyPropertyByName) 4,800,209 → 80 B −100.00% −48 B 6.28 → 2.83 ms −54.9% ±0.6%
Editable ComboBox, DisplayMemberPath over DO items, 200 selections 16,941,852 → 16,961,880 B +0.12% +100 B 119.02 → 119.12 ms +0.1% (noise) ±3.9%

The DP-by-name reflection cache works as intended: a lookup goes from 48 B and two reflection calls to a cache hit, 55% faster. Its callers in Uno today are attached-property name resolution and ComboBox DisplayMemberPath over DependencyObject items, and in the end-to-end ComboBox scenario the saving is lost among everything else a selection does (that row even shows +100 B per selection). The scenario workloads are unchanged, because master already creates the store's maps lazily (see the note above).

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
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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


Review summary

Verdict: ship after the description is reconciled with the diff. I found 1 issue, a minor description/diff mismatch, and no blockers.

I reviewed the MetadataAPI cache change, the AlcCacheSweep refactor, the hot-reload clearing and the DEBUG validation reordering. I did not build or run the tests. This is code review by inspection only.

  • The ConcurrentDictionary switch is correct for non-UI-thread property-path resolution.
  • Caching a null result only when no matching member exists avoids poisoning the entry before the static initializer runs.
  • Clearing the cache in RuntimeTypeMetadataUpdateHandler is correct.
  • Reusing AlcCacheSweep through the new typeSelector overload removes duplicated sweep logic.

Cross-cutting notes

  • Race: TryGetValue followed by [key] = property is not atomic. It is benign here because the resolution is deterministic and idempotent, so the worst case is a redundant reflection lookup.
  • The two new test files carry the validation. Please confirm they run in CI.
    · branch dev/mazi/perf2026-dpstore

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.

// e.g. ScrollContentPresenter, for which using the Name property should not fail.
&& !isMixinFrameworkElement
// Evaluate the extra type checks last; validation runs on every property access in DEBUG.
&& !IsMixinFrameworkElement()

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.

The PR description says DependencyObjectStore now creates its inherited-property and callback-token maps lazily, but this file's diff only reorders the DEBUG owner validation. _propertyChangedTokens is already ??=-allocated on origin/master, and the diff has no change to the inherited-property map. Please either fix the description or point to where the lazy-allocation change lives. As written, Given_DependencyObject_LazyState may be covering behavior this PR doesn't change.

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 18, 2026
@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

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund MartinZikmund changed the title perf(dp): Lazy store maps and DP metadata cache perf(dp): Cache DependencyProperty lookups by name Nov 18, 2026
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 247320 found UI Test snapshots differences: skia-linux-screenshots: 238, skia-windows-screenshots: 262

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_StructureAndProps.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • Buttons.png-dark
    • Buttons.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
  • skia-windows-screenshots: 262 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_AutomationId.png-dark
    • BenchmarkDotNet.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AutomationProperties_AutomationId.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • AnimatedVisualsTestbedPage.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