Repository navigation
perf(uno-ui): Use the cached bool boxes in generated DP setters - #24242
MartinZikmund wants to merge 1 commit into
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Pull request overview
This PR updates Uno.UI’s dependency-property source generators to avoid per-set allocations for bool DependencyProperty setters by emitting SetValue(..., global::Uno.UI.Helpers.Boxes.Box(value)) instead of SetValue(..., value) (which boxes).
Changes:
- Update
DependencyPropertyGeneratorto box-cacheboolvalues in generated attached and instance setters. - Update
DependencyPropertyMixinGeneratorto box-cacheboolvalues in generated mixin-property setters.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/SourceGenerators/Uno.UI.SourceGenerators.Internal/Mixins/DependencyPropertyMixinGenerator.cs | Emit Boxes.Box(value) for generated bool mixin property setters to avoid boxing allocations. |
| src/SourceGenerators/Uno.UI.SourceGenerators.Internal/DependencyObject/DependencyPropertyGenerator.cs | Introduce a shared helper to emit Boxes.Box(value) for generated bool DP setters (attached + instance). |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| private static string GetBoxedValueExpression(string propertyTypeName) | ||
| => propertyTypeName == "bool" | ||
| ? "global::Uno.UI.Helpers.Boxes.Box(value)" | ||
| : "value"; |
| // SetValue takes an object, so a bool would be boxed on every set. Uno.UI already keeps the | ||
| // two boxed instances, and these properties (IsTabStop, focus flags and the like) are set | ||
| // often enough for a 24-byte allocation each time to be worth avoiding. | ||
| var setterValue = dp.PropertyType == "bool" ? "global::Uno.UI.Helpers.Boxes.Box(value)" : "value"; | ||
| sb.AppendLine($"\t\t\tset {{ this.SetValue({dp.Name}Property, {setterValue}); }}"); |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24242/wasm-skia-net9/index.html |
|
@MartinZikmund FYI, #12677 Feel free to continue with your PR if it's more ready. You can take also a look at mine to see if there are interesting differences and try to take the best of the two worlds. |
SetValue takes an object, so a bool is boxed at the call site -- 24 bytes on every set. Uno.UI already keeps the two boxed instances in Uno.UI.Helpers.Boxes and uses them by hand in a few places, but both DependencyProperty generators emitted the plain SetValue(prop, value), so every generated bool setter allocated. Emit Boxes.Box(value) for bool properties in both generators, and pass value through unchanged for every other type, so any bool DP added later gets this automatically. This cannot change behaviour: AreDifferent takes the `newValue is ValueType` branch for a boxed bool and compares with object.Equals, a value comparison, so change detection never depended on box identity. Measured (specs/059-performance-improvements): toggling Control.IsEnabled, a generated bool DP, drops from 72 B to 48 B per set -- exactly 24 B, one box, byte-identical across runs. DependencyPropertyGenerator golden tests 6/6 pass; 684 control and framework runtime tests show identical pass/fail sets against a baseline build. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
cf83f33 to
f17201f
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24242/wasm-skia-net9/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24242/wasm-skia-net9/index.html |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Code review assessment: the emitted setters still call SetValue with the same Boolean value, now using the existing true/false boxes; non-Boolean types retain their previous expression. I checked helper accessibility for the actual consumers, including the friend unit-test assembly. This is a managed allocation optimization, not a change to WinUI Boolean/DP semantics. No blocking source issue found. Add golden assertions for both instance/attached and mixin Boolean setters to protect the new code-generation branch. Any failed automated-review check remains a separate merge gate.
|
Superseded by #12677, which has been brought up to current That PR does the same thing generalised: the generated setter boxing now covers The One correction worth recording: this PR's comment asserted that |
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes unoplatform#24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes unoplatform#24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes #24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes #24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes unoplatform#24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes #24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
Generated setters and DefaultValue metadata now pass the cached box for bool, int and double instead of boxing on every set and every registration. Boxes is internal to Uno.UI, so the generators check that it is actually accessible from the compilation and fall back to the plain value otherwise - any other consumer of [GeneratedDependencyProperty] keeps compiling. Supersedes unoplatform#24242. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BDvvr5VMr8KxRygFWfc1q4 Co-Authored-By: Youssef Victor <[email protected]>
GitHub Issue: closes #24241
PR Type:
🔄 Refactoring (no functional changes, no api changes)
What changed? 🚀
DependencyObject.SetValuetakes anobject, so aboolis boxed at the call site — 24 bytes on every set. Uno.UI already keeps the two boxed instances inUno.UI.Helpers.Boxesand uses them by hand in a few places, but both DependencyProperty generators emitted the plainSetValue(prop, value), so every generatedboolsetter allocated.Both generators now emit
SetValue(XProperty, global::Uno.UI.Helpers.Boxes.Box(value))when the property type isbool, and passvaluethrough unchanged for every other type — so anyboolDP added later gets this automatically.DependencyPropertyGenerator— both emission sites (attached and instance setters)DependencyPropertyMixinGenerator— its data model declares 13boolpropertiesUno.UI.Helpers.Boxesis internal to Uno.UI, which is the only assembly using[GeneratedDependencyProperty]; any other consumer would get a compile error here rather than a silent behaviour change.Measured impact 📊
1,000 × toggling
Control.IsEnabled(a[GeneratedDependencyProperty]bool) on aButton, 3 runs, median:Byte-identical across every run in both configurations — exactly 24 B per set, one box. The remaining 48 B is the change-notification path and is unrelated to this change.
Measured with a headless harness that project-references the real framework, rebuilt from the working tree; full methodology and raw runs in
specs/059-performance-improvements/evidence.md(PR #24238).Why it cannot change behaviour ✅
DependencyObject.AreDifferent(DependencyObject.Store.cs:2313) takes thenewValue is ValueTypebranch for a boxedbooland compares withobject.Equals— a value comparison:Change detection therefore never depended on box identity, so sharing the two boxed instances is invisible to it.
Validation ✅
DependencyPropertyGeneratorgolden tests: 6 run, 6 passed.Given_Control,Given_Button,Given_CheckBox,Given_ToggleSwitch,Given_RadioButton,Given_VisualStateManager,Given_UIElement,Given_FrameworkElement: 684 run, 658 passed, 2 skipped, 26 failed, compared as sets of failing test names against a baseline build — 0 new failures, 0 newly passing.Follow-up (not in this PR)
151 hand-written
boolDP setters inUno.UIstill callSetValue(XProperty, value)directly and pay the same 24 B — including hot ones on the base types:UIElement.IsHitTestVisible(measured 72 B/set) andUIElement.IsTabStop(24 B/set) are hand-written, not generated. That is a 151-site mechanical sweep and is better done separately.PR Checklist ✅
Screenshots Compare Test Runresults. — to check once CI has run