Repository navigation
Description
What would you like to be added? π‘
DependencyObject.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 for exactly this reason (Uno.UI.Helpers.Boxes.BooleanBoxes, with a Boxes.Box(bool) helper) and uses them by hand in a handful of places. But both DependencyProperty generators emit the plain form:
private void SetIsEnabledValue(bool value) => SetValue(IsEnabledProperty, value);
// ^^^^^ boxed, every timeso every generated bool setter allocates.
Both generators should emit SetValue(XProperty, global::Uno.UI.Helpers.Boxes.Box(value)) when the property type is bool, passing value through unchanged for every other type β which also makes it automatic for any bool DP added later.
src/SourceGenerators/Uno.UI.SourceGenerators.Internal/DependencyObject/DependencyPropertyGenerator.cssrc/SourceGenerators/Uno.UI.SourceGenerators.Internal/Mixins/DependencyPropertyMixinGenerator.cs(its data model declares 13boolproperties)
Why is this needed? π€
bool dependency properties are set constantly β visual-state changes, IsEnabled propagation down a subtree, focus and tab-stop flags β and each set allocates a box that is immediately discarded.
Measured impact π
1,000 Γ toggling Control.IsEnabled (a [GeneratedDependencyProperty] bool) on a Button, 3 runs, median:
| Metric | Before | After | Ξ |
|---|---|---|---|
| alloc / set | 72.0 B | 48.0 B | β33.3 % |
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.
Why it cannot change behaviour β
DependencyObject.AreDifferent (DependencyObject.Store.cs:2313) takes the newValue is ValueType branch for a boxed bool and compares with object.Equals β a value comparison, not a reference comparison:
if (newValue is ValueType || newValue is string)
{
return !object.Equals(previousValue, newValue);
}So change detection never depended on box identity, and sharing the two boxed instances is invisible to it.
Renderer π¨
- Skia
For which platforms π±π»π₯οΈ
All platforms π
Anything else we need to know? π¬
Follow-up, deliberately not included: 151 hand-written bool DP setters in Uno.UI still call SetValue(XProperty, value) directly and pay the same 24 B, including hot ones on the base types β UIElement.IsHitTestVisible (72 B/set measured) and UIElement.IsTabStop (24 B/set measured) are both hand-written, not generated. That is a 151-site mechanical sweep and is worth doing separately.
Found by allocation profiling and measured before/after with a headless harness that project-references the real framework. Full methodology and raw runs: specs/059-performance-improvements/evidence.md.
Activity