Reduce boolean boxes across the framework - #35596
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35596Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35596" |
|
Hey there @@pictos! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
/review -b feature/refactor-copilot-yml |
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| global using Microsoft.Maui; | ||
| global using Microsoft.Maui.Handlers; | ||
| global using Microsoft.Maui.Platform; | ||
| global using Microsoft.Maui.Controls.Internals; |
There was a problem hiding this comment.
[critical] Platform-Specific Code Scoping / Build - Adding Microsoft.Maui.Controls.Internals as a global using imports every internal Controls type into every file in this project. On iOS files that also use Foundation and unqualified [Preserve], this makes PreserveAttribute ambiguous between Foundation.PreserveAttribute and Microsoft.Maui.Controls.Internals.PreserveAttribute, causing the iOS build to fail. Please keep BooleanBoxes references explicit, use a targeted alias/static using, or add local usings only where needed instead of globally importing the whole Internals namespace.
|
/review -b feature/refactor-copilot-yml |
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
|
/review -b feature/refactor-copilot-yml |
|
I don't think the bot suggestion makes sense. I believe to have one API is better |
…ols.Core Replace raw true/false literals with BooleanBoxes.TrueBox/FalseBox in SetValue and SetValueFromRenderer calls for bool-typed BindableProperties. Added using Microsoft.Maui.Controls.Internals to ShellPageRendererTracker.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ties in Controls.Core Replace raw true/false/default(bool) literals with BooleanBoxes.TrueBox/FalseBox in BindableProperty.CreateAttached and CreateAttachedReadOnly calls for bool-typed properties. Added using Microsoft.Maui.Controls.Internals to 6 files that did not already have it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… Controls.Core Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cator The global using Microsoft.Maui.Controls.Internals caused CS0104 ambiguous reference errors for PreserveAttribute in iOS files that also import Foundation. Remove the global using and add an explicit using to the one file that was missing it (ActivityIndicator.cs). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…boxing All public bool property setters that previously called SetValue(Prop, value) now call SetValue(Prop, BooleanBoxes.Box(value)) to eliminate per-assignment heap allocations. This completes the boxing optimization across: - VisualElement (IsVisible, IsEnabled, InputTransparent, IsFocused) - CheckBox, Switch, RadioButton (IsChecked, IsToggled) - ActivityIndicator, RefreshView, ListView, CarouselView, and others - SetterSpecificity overloads (FromHandler) also updated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add BooleanBoxesProductionTests class with Assert.Same checks on: * DefaultValue for representative BindableProperties * GetValue() after setter calls (verifies cached box is stored) - Fix CoerceIsEnabledProperty and CoerceInputTransparentProperty in VisualElement to return BooleanBoxes.Box(...) / BooleanBoxes.FalseBox instead of raw bool literals (which would allocate a new box) - Fix CoerceIsEnabledProperty in MenuItem similarly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
63cd5ab to
f0dbf63
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from dotnet#35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with dotnet#35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from dotnet#35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with dotnet#35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
<!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> <!-- Enter description of the fix in this section --> This is a follow up from #35303, that implements the `BooleanBoxes` class and use inside the `Control` project [Use the same solution that the WPF team uses](https://github.com/dotnet/wpf/blob/b325a186ebcead7fddfde43c118f6a807397de35/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/KnownBoxes.cs#L10), cache the boxed `true` and `false` values, and use it instead of boxing a new boolean on every operation. <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Relates with #35302 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Pedro Jesus <pedrojesus@Pedros-MacBook-Pro.local>
Description of Change
This is a follow up from #35303, that implements the
BooleanBoxesclass and use inside theControlprojectUse the same solution that the WPF team uses, cache the boxed
trueandfalsevalues, and use it instead of boxing a new boolean on every operation.Issues Fixed
Relates with #35302