Repository navigation
perf(xaml): Generate a fast path for TemplateBinding - #26584
MartinZikmund wants to merge 2 commits into
Conversation
Co-Authored-By: Martin Zikmund <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu1LMuUpziGZWHVDmpX
Co-Authored-By: Martin Zikmund <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu1LMuUpziGZWHVDmpX
There was a problem hiding this comment.
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.
|
Claude finished @MartinZikmund's task in 30s —— View job Review of #26584Verdict: fix-first (minor). The design is sound. The fast path is isolated behind Findings (3 inline, all medium/low):
Cross-cutting:
|
|
Tick the box to add this pull request to the merge queue (same as
|
|
|
||
| // No validation hook: a TemplateBinding never resolves a source path, so it can't be a validation source. | ||
| details.SetBinding(bindingExpression); | ||
| _bindings = _bindings.Add(bindingExpression); |
There was a problem hiding this comment.
details.ClearBinding() disposes the previous expression but never removes it from _bindings. Re-applying a template binding to the same target (template re-applied or pooled, hot reload) leaves disposed expressions in the list. ApplyTemplateBindingParents, the suspend/resume loops and the theme-resource loops then iterate over them. ApplyTemplateBindingParent returns early when _disposed, so this is not a correctness bug, but the list grows. Check how SetBinding (line ~174) handles replacement and remove the old expression the same way.
| } | ||
|
|
||
| _templatedParentWeakRef = parentReference; | ||
| _properties?.ApplyTemplateBindingParents(); |
There was a problem hiding this comment.
ApplyTemplateBindingParents() is new behavior for all template bindings, including the general Binding { RelativeSource = TemplatedParent } fallback. Those were previously re-resolved through the existing paths (ApplyTemplateBindingParent calls elsewhere, DataContext propagation). Re-applying them here may double-evaluate them. It also fires on every templated-parent change, including the common set-once case. Please add a runtime test that counts evaluations or setter invocations for a general-path template binding. Alternatively, restrict this call to fast-path expressions (TemplateBindingSourceProperty is not null).
| { | ||
| if (scope.Object.Type.Name == "ControlTemplate" | ||
| && FindMember(scope.Object, "TargetType")?.Value is { } targetType) | ||
| { |
There was a problem hiding this comment.
The fallback to CurrentStyleTargetType assumes the enclosing Style's TargetType equals the templated parent type. For a ControlTemplate with no TargetType inside a Setter of Style TargetType="Control", this binds to Control.XProperty even when the template's real target is a derived type. This is the right owner in most cases, but it differs from the old reflection path, which resolved the name at runtime against the actual templated parent. The generator-level snapshot tests only cover templates that declare TargetType. Please add a case for a template without TargetType, or return null here so those uses keep the general fallback.
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 247318 found UI Test snapshots differences: Details
|
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
XamlOptionalChangespart. This piece is always on, so it gets its own review.The XAML generator now compiles a simple one-way
{TemplateBinding}into direct source/targetDependencyPropertyreferences (BindingHelper.SetTemplateBinding). That skips allocating aBinding,RelativeSource,BindingPath, its path nodes and the reflection-based target setter. Complex paths/options keep the general binding fallback.ParentBindingreconstruction.DependencyObject.Storedetects template bindings throughBindingExpression.IsTemplateBindinginstead of readingParentBinding.RelativeSource, so the lazyParentBindingisn't materialized.{TemplateBinding}uses in Uno.UI qualify.Upstream counterpart: WinUI removed the per-TemplateBinding handler allocation in bbb46616.
Validation
Uno.UI.UnitTests(net11.0) andUno.UI.SourceGenerators.Tests.BindingTests.Given_Bindingunit tests 13/13. All source-generator tests 639 passed, 0 failed, 7 skipped (including the new fast-path snapshots).Performance
Headless Skia app with Fluent resources (x64, net10.0,
DOTNET_TieredCompilation=0), one process per scenario, 4 interleaved A/B rounds againstmaster. Allocations are UI-thread bytes and exact: amaster-vs-masternull 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.Buttons, built + laid outButtons with local values overriding the styleBorder+ child (no templates)Tagset/getThe generated fast path removes about 25 KB per templated Fluent
Button(−22% of everything a Button allocates to build and lay out), and about 28 KB per control on a mixed page. Untemplated elements and visual-state changes are unaffected, as expected. This is the largest single win of the Perf2026 port.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01TXMNu1LMuUpziGZWHVDmpX