Skip to content

Reduce boolean boxes across the framework#35596

Merged
kubaflo merged 11 commits into
dotnet:inflight/currentfrom
pictos:pj/avoid-bool-boxing
Jun 14, 2026
Merged

Reduce boolean boxes across the framework#35596
kubaflo merged 11 commits into
dotnet:inflight/currentfrom
pictos:pj/avoid-bool-boxing

Conversation

@pictos

@pictos pictos commented May 23, 2026

Copy link
Copy Markdown
Contributor

Description of Change

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, cache the boxed true and false values, and use it instead of boxing a new boolean on every operation.

Issues Fixed

Relates with #35302

@github-actions

github-actions Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35596

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35596"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label May 23, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added area-controls-general General issues that span multiple controls, or common base classes such as View or Element platform/android platform/ios platform/tizen Samsung Tizen Devices (TV) labels May 23, 2026
@kubaflo

kubaflo commented May 24, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@MauiBot MauiBot added s/agent-review-incomplete s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels May 24, 2026
@kubaflo

kubaflo commented May 24, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 findings

See inline comments for details.

Comment thread src/Controls/src/Core/GlobalNamespaces.cs Outdated
@kubaflo

kubaflo commented May 25, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/refactor-copilot-yml

MauiBot

This comment was marked as outdated.

@pictos

pictos commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

I don't think the bot suggestion makes sense. I believe to have one API is better

@pictos pictos force-pushed the pj/avoid-bool-boxing branch from dfa1325 to 63cd5ab Compare June 11, 2026 21:31
@kubaflo

kubaflo commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

/review -b feature/enhanced-reviewer -p android

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Jun 11, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

@pictos — new AI review results are available based on this last commit: 63cd5ab.
Add production regression tests and fix coerce functions boxing To request a fresh review after new comments or commits, comment /review rerun.

Gate Failed Code Review In Review Confidence Low Platform Android

Review Sessions — click to expand
Gate — Test Before & After Fix

Gate Result: ❌ FAILED

Platform: ANDROID · Base: main · Merge base: dd5b6d2e

🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.

Test Without Fix (expect FAIL) With Fix (expect PASS)
🧪 BooleanBoxesTests BooleanBoxesTests ❌ PASS — 112s ✅ PASS — 110s
🔴 Without fix — 🧪 BooleanBoxesTests: PASS ❌ · 112s
  Determining projects to restore...
  Restored /home/vsts/work/1/s/src/TestUtils/src/TestUtils/TestUtils.csproj (in 4.22 sec).
  Restored /home/vsts/work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 148 ms).
  Restored /home/vsts/work/1/s/src/Essentials/src/Essentials.csproj (in 3.33 sec).
  Restored /home/vsts/work/1/s/src/Core/src/Core.csproj (in 415 ms).
  Restored /home/vsts/work/1/s/src/Core/maps/src/Maps.csproj (in 9.59 sec).
  Restored /home/vsts/work/1/s/src/Controls/src/Xaml/Controls.Xaml.csproj (in 128 ms).
  Restored /home/vsts/work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 92 ms).
  Restored /home/vsts/work/1/s/src/Controls/Maps/src/Controls.Maps.csproj (in 53 ms).
  Restored /home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj (in 1.69 sec).
  1 of 10 projects are up-to-date for restore.
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Graphics -> /home/vsts/work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Essentials -> /home/vsts/work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Core -> /home/vsts/work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
  Controls.BindingSourceGen -> /home/vsts/work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Maps -> /home/vsts/work/1/s/artifacts/bin/Maps/Debug/net10.0/Microsoft.Maui.Maps.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Controls.Core -> /home/vsts/work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Controls.Xaml -> /home/vsts/work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0/Microsoft.Maui.Controls.Xaml.dll
  ##vso[build.updatebuildnumber]10.0.80-ci+azdo.14353332
  Controls.Maps -> /home/vsts/work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0/Microsoft.Maui.Controls.Maps.dll
  TestUtils -> /home/vsts/work/1/s/artifacts/bin/TestUtils/Debug/netstandard2.0/Microsoft.Maui.TestUtils.dll
  Controls.Core.UnitTests -> /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.16]   Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.55]   Discovered:  Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.56]   Starting:    Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.64]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed FalseBoxIsBoxedFalse [11 ms]
  Passed BoxNullableNullReturnsNull [< 1 ms]
  Passed BoxFalseReturnsFalseBox [< 1 ms]
  Passed BoxReturnsSameReferenceOnRepeatedCalls [< 1 ms]
  Passed BoxNullableFalseReturnsFalseBox [< 1 ms]
  Passed BoxTrueReturnsTrueBox [< 1 ms]
  Passed TrueBoxIsBoxedTrue [< 1 ms]
  Passed BoxNullableTrueReturnsTrueBox [< 1 ms]
  Passed TrueBoxAndFalseBoxAreDifferentInstances [< 1 ms]

Test Run Successful.
Total tests: 9
     Passed: 9
 Total time: 2.2338 Seconds

🟢 With fix — 🧪 BooleanBoxesTests: PASS ✅ · 110s
  Determining projects to restore...
  Restored /home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj (in 1.04 sec).
  Restored /home/vsts/work/1/s/src/Controls/src/Xaml/Controls.Xaml.csproj (in 114 ms).
  Restored /home/vsts/work/1/s/src/Controls/Maps/src/Controls.Maps.csproj (in 1.29 sec).
  Restored /home/vsts/work/1/s/src/Controls/src/Core/Controls.Core.csproj (in 52 ms).
  Restored /home/vsts/work/1/s/src/TestUtils/src/TestUtils/TestUtils.csproj (in 13 ms).
  Restored /home/vsts/work/1/s/src/Controls/src/BindingSourceGen/Controls.BindingSourceGen.csproj (in 62 ms).
  Restored /home/vsts/work/1/s/src/Essentials/src/Essentials.csproj (in 24 ms).
  Restored /home/vsts/work/1/s/src/Graphics/src/Graphics/Graphics.csproj (in 49 ms).
  Restored /home/vsts/work/1/s/src/Core/maps/src/Maps.csproj (in 75 ms).
  Restored /home/vsts/work/1/s/src/Core/src/Core.csproj (in 101 ms).
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Graphics -> /home/vsts/work/1/s/artifacts/bin/Graphics/Debug/net10.0/Microsoft.Maui.Graphics.dll
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Essentials -> /home/vsts/work/1/s/artifacts/bin/Essentials/Debug/net10.0/Microsoft.Maui.Essentials.dll
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Core -> /home/vsts/work/1/s/artifacts/bin/Core/Debug/net10.0/Microsoft.Maui.dll
  Controls.BindingSourceGen -> /home/vsts/work/1/s/artifacts/bin/Controls.BindingSourceGen/Debug/netstandard2.0/Microsoft.Maui.Controls.BindingSourceGen.dll
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Maps -> /home/vsts/work/1/s/artifacts/bin/Maps/Debug/net10.0/Microsoft.Maui.Maps.dll
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Controls.Core -> /home/vsts/work/1/s/artifacts/bin/Controls.Core/Debug/net10.0/Microsoft.Maui.Controls.dll
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  ##vso[build.updatebuildnumber]10.0.90-ci+azdo.14353332
  Controls.Maps -> /home/vsts/work/1/s/artifacts/bin/Controls.Maps/Debug/net10.0/Microsoft.Maui.Controls.Maps.dll
  Controls.Xaml -> /home/vsts/work/1/s/artifacts/bin/Controls.Xaml/Debug/net10.0/Microsoft.Maui.Controls.Xaml.dll
  TestUtils -> /home/vsts/work/1/s/artifacts/bin/TestUtils/Debug/netstandard2.0/Microsoft.Maui.TestUtils.dll
  Controls.Core.UnitTests -> /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.1 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.0)
[xUnit.net 00:00:00.16]   Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.37]   Discovered:  Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.38]   Starting:    Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.47]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed FalseBoxIsBoxedFalse [11 ms]
  Passed BoxNullableNullReturnsNull [< 1 ms]
  Passed BoxFalseReturnsFalseBox [< 1 ms]
  Passed BoxReturnsSameReferenceOnRepeatedCalls [< 1 ms]
  Passed BoxNullableFalseReturnsFalseBox [< 1 ms]
  Passed BoxTrueReturnsTrueBox [< 1 ms]
  Passed TrueBoxIsBoxedTrue [< 1 ms]
  Passed BoxNullableTrueReturnsTrueBox [< 1 ms]
  Passed TrueBoxAndFalseBoxAreDifferentInstances [< 1 ms]

Test Run Successful.
Total tests: 9
     Passed: 9
 Total time: 2.1658 Seconds

⚠️ Failure Details

  • BooleanBoxesTests PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (79 files)
  • eng/Versions.props
  • eng/pipelines/ci-copilot.yml
  • src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs
  • src/Controls/src/Core/AppLinkEntry.cs
  • src/Controls/src/Core/Cells/Cell.cs
  • src/Controls/src/Core/Cells/SwitchCell.cs
  • src/Controls/src/Core/CheckBox/CheckBox.cs
  • src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs
  • src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs
  • src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs
  • src/Controls/src/Core/CompressedLayout.cs
  • src/Controls/src/Core/ContentPage/ContentPage.cs
  • src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs
  • src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs
  • src/Controls/src/Core/Entry/Entry.cs
  • src/Controls/src/Core/FlyoutPage/FlyoutPage.cs
  • src/Controls/src/Core/FontImageSource.cs
  • src/Controls/src/Core/Frame/Frame.cs
  • src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs
  • src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs
  • src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs
  • src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs
  • src/Controls/src/Core/IndicatorView/IndicatorView.cs
  • src/Controls/src/Core/InputView/InputView.cs
  • src/Controls/src/Core/Interactivity/MultiCondition.cs
  • src/Controls/src/Core/Interactivity/PropertyCondition.cs
  • src/Controls/src/Core/Items/CarouselView.cs
  • src/Controls/src/Core/Items/GroupableItemsView.cs
  • src/Controls/src/Core/Items/ReorderableItemsView.cs
  • src/Controls/src/Core/Layout/Layout.cs
  • src/Controls/src/Core/ListView/ListView.cs
  • src/Controls/src/Core/Menu/MenuBar.cs
  • src/Controls/src/Core/Menu/MenuBarItem.cs
  • src/Controls/src/Core/Menu/MenuItem.cs
  • src/Controls/src/Core/NavigationPage/NavigationPage.cs
  • src/Controls/src/Core/Page/Page.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/Button.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ImageButton.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ListView.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ViewCell.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs
  • src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs
  • src/Controls/src/Core/PlatformConfiguration/TizenSpecific/Application.cs
  • src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs
  • src/Controls/src/Core/PlatformConfiguration/TizenSpecific/VisualElement.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/InputView.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Label.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/SearchBar.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs
  • src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/WebView.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Application.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Entry.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Slider.cs
  • src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs
  • src/Controls/src/Core/RadioButton/RadioButton.cs
  • src/Controls/src/Core/RefreshView/RefreshView.cs
  • src/Controls/src/Core/Shapes/ArcSegment.cs
  • src/Controls/src/Core/Shapes/PathFigure.cs
  • src/Controls/src/Core/Shell/BackButtonBehavior.cs
  • src/Controls/src/Core/Shell/BaseShellItem.cs
  • src/Controls/src/Core/Shell/SearchHandler.cs
  • src/Controls/src/Core/Shell/Shell.cs
  • src/Controls/src/Core/StateTrigger.cs
  • src/Controls/src/Core/SwipeView/SwipeItem.cs
  • src/Controls/src/Core/Switch/Switch.cs
  • src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs
  • src/Controls/src/Core/TableView/TableView.cs
  • src/Controls/src/Core/TemplatedItemsList.cs
  • src/Controls/src/Core/UriImageSource.cs
  • src/Controls/src/Core/VisualElement/VisualElement.cs

New files (not reverted):

  • src/Controls/src/Core/Internals/BooleanBoxes.cs

UI Tests — CheckBox,CollectionView,Entry,FlyoutPage,Frame,IndicatorView,Layout,ListView,Navigation,Page,RadioButton,RefreshView,Shape,Shell,SwipeView,Switch,TabbedPage,TableView

Detected UI test categories: CheckBox,CollectionView,Entry,FlyoutPage,Frame,IndicatorView,Layout,ListView,Navigation,Page,RadioButton,RefreshView,Shape,Shell,SwipeView,Switch,TabbedPage,TableView

Deep UI tests — 23 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
CheckBox 23/23 ✓
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

Regression Cross-Reference

🔍 Regression Cross-Reference

🟡 Overlaps with prior bug-fix PRs — same files modified, but no exact line revert detected.

File Fix PR Fixed issue(s)
src/Controls/src/Core/FlyoutPage/FlyoutPage.cs #34485 #33355

🧪 Regression Tests to Verify

These tests were added by the overlapping fix PRs. Running them to verify no side-effect regressions:

Fix PR Type Test Filter
#34485 DeviceTest MemoryTests MemoryTests

🧪 Regression Test Results

⏭️ SKIPPED — 0 passed, 0 failed, 1 skipped

Fix PR Test Type Result
#34485 MemoryTests DeviceTest ⏭️ ERROR

Pre-Flight — Context & Validation

Issue: #unknown - unavailable (GitHub CLI authentication unavailable)
PR: #35596 - unavailable from GitHub; local branch pr-review-35596
Platforms Affected: Android primary test target; Controls/Core behavior broadly; CI/workflow files also changed in PR diff
Files Changed: 82 implementation/infrastructure, 2 test/documentation-support (local diff against origin/main; exact PR metadata unavailable)

Key Findings

  • GitHub CLI authentication is unavailable, so PR body, linked issue, comments, prior reviews, and required-check status could not be fetched.
  • Local diff shows the PR primarily introduces BooleanBoxes and rewrites many Controls bool bindable-property defaults/setters to use shared boxed bool instances.
  • Local diff also includes Copilot review pipeline/script changes unrelated to the Controls allocation fix.
  • Independent code review found the Controls BooleanBoxes strategy behaviorally sound, but flagged .github/workflows/review-trigger.yml broadening pull-requests permission from read to write as an unrelated least-privilege issue.

Code Review Summary

Verdict: NEEDS_CHANGES
Confidence: low
Errors: 1 | Warnings: 1 | Suggestions: 1

Key code review findings:

  • .github/workflows/review-trigger.yml:154 changes pull-requests: read to pull-requests: write; job appears to only need PR read access and issue label write access.
  • ⚠️ eng/pipelines/ci-copilot.yml:1782 invokes token aggregation through a repo-relative path instead of the trusted-copy convention.
  • 💡 src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs:2 has an unused import.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #35596 Broad Controls call-site replacement: bool bindable-property defaults use BooleanBoxes.TrueBox/FalseBox, setters use BooleanBoxes.Box(value) ⏳ PENDING (Gate failed before this task; not re-run) Many Controls files + tests Original PR fix; broad but directly avoids call-site boxing for changed setters.

Code Review — Deep Analysis

Code Review — PR #35596

Independent Assessment

What this changes: Adds cached boxed Boolean values across Controls bindable properties/setters, plus Copilot review token-usage telemetry and review workflow/script updates.
Inferred motivation: Reduce bool boxing allocations and improve Copilot review observability/retry behavior.

Reconciliation with PR Narrative

Author claims: Unavailable — gh is unauthenticated.
Agreement/disagreement: PR narrative, linked issues, comments unavailable; reviewed local diff against origin/main.

Prior Review Reconciliation

Prior reviews unavailable: gh authentication is unavailable, so top-level reviews, inline comments, and issue comments could not be queried.

Blast Radius Assessment

  • Runs for all instances: Yes — many shared Controls bindable properties and CI workflow paths.
  • Startup impact: Low for Controls; CI workflow impact is infrastructure-wide.
  • Static/shared state: Yes — immutable boxed bool singletons.

CI Status

  • Required-check result: unavailable
  • Classification: undetermined
  • Action taken: gh pr checks --required unavailable due missing auth; confidence capped low.

Findings

❌ Error — Unnecessary PR write permission

.github/workflows/review-trigger.yml:154 changes pull-requests: read to pull-requests: write, but the job only reads PR metadata and manages labels through issues: write. This violates least-privilege guidance and grants unnecessary PR mutation capabilities. Revert to pull-requests: read.

⚠️ Warning — Trusted script convention deviation

eng/pipelines/ci-copilot.yml:1782 invokes .github/scripts/shared/Aggregate-CopilotTokenUsage.ps1 via repo-relative path instead of the trusted-copy convention. Risk appears low in this fresh checkout stage, but this should be documented or aligned with $TRUSTED conventions.

💡 Suggestion — Test cleanup

src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs:2 has an unused Microsoft.Maui.Controls.Shapes import and lacks a trailing newline.

Failure-Mode Probing

  • Unused feature path: BooleanBoxes changes preserve bool values; cached boxes are immutable.
  • defaultValueCreator: Shell.NavBarHasShadowProperty still boxes creator results, so optimization is incomplete but not behavioral.
  • Workflow compromise: broadened pull-requests: write increases token blast radius unnecessarily.

Verdict: NEEDS_CHANGES

Confidence: low — CI/PR narrative/prior reviews unavailable.
Summary: Main Controls optimization looks sound, and PowerShell parsing plus aggregation smoke test passed. The workflow permission expansion should be fixed before merge.


Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix Central bool canonicalization in BindableObject/BindableProperty plus internal bool SetValue overloads ⚠️ BLOCKED 2 infra files + reverted broad call-site changes Primary BooleanBoxes tests passed; Android MemoryTests hung in xharness instrumentation. Most allocation-aggressive central alternative.
2 try-fix Default-value-only canonicalization in BindableProperty ❌ FAIL 1 infra file + reverted broad call-site changes Setter storage assertions failed; explicit bool sets still box before SetValue(object).
3 try-fix Storage-boundary canonicalization in BindableObject.SetValueCore/BindableProperty, no bool overloads ⚠️ BLOCKED 2 infra files + reverted broad call-site changes Primary BooleanBoxes tests passed; Android MemoryTests timed out in xharness instrumentation. Cleanest non-invasive central alternative, but does not remove transient call-site boxing.
PR PR #35596 Broad call-site replacement using BooleanBoxes defaults and setters ❌ Gate failed (pre-existing gate result) Many Controls files Original PR; gate was already failed before this task and was not re-run per instruction.

Cross-Pollination

Model Round New Ideas? Details
maui-expert-reviewer 1 Yes Proposed central canonicalization, default-only canonicalization, internal typed helper/factory, and specialized bool storage.
maui-expert-reviewer 2 No After candidate results, reviewer found no non-trivial remaining approaches: remaining options are trivial variants of candidates 1/3 or too invasive (BindableProperty<T>/unboxed storage rewrite).

Exhausted: Yes
Selected Fix: None proven — candidates 1 and 3 passed primary tests but mandatory Android MemoryTests were blocked by xharness instrumentation timeout; candidate 2 failed primary tests. Candidate 3 is the best unproven alternative on simplicity/centralization, while candidate 1 is stronger for transient allocation reduction but adds overload complexity. Neither can be declared passing without Android MemoryTests completion.

Per-Candidate Details

  • try-fix-1: see ../try-fix-1/content.md, fix.diff, test-output.log, regression-output.log, and analysis.md.
  • try-fix-2: see ../try-fix-2/content.md, fix.diff, test-output.log, and analysis.md.
  • try-fix-3: see ../try-fix-3/content.md, fix.diff, test-output.log, regression-output.log, and analysis.md.

Report — Final Recommendation

Comparative Report — PR #35596

Candidates compared

Rank Candidate Regression status Assessment
1 pr-plus-reviewer Gate failed / Android regression undetermined Best available candidate. It preserves the PR's direct call-site boxing reduction and applies the expert reviewer's required security fix by restoring pull-requests: read in review-trigger.yml.
2 pr Gate failed / Android regression undetermined The BooleanBoxes fix is sound, but the raw PR keeps the over-scoped pull-requests: write workflow permission, so it ranks below the reviewer-applied PR candidate.
3 try-fix-1 Primary PASS; Android MemoryTests BLOCKED Central canonicalization plus bool SetValue overloads is allocation-strong and broad, but the mandatory Android regression did not complete. It also adds API-surface/internal-overload complexity.
4 try-fix-3 Primary PASS; Android MemoryTests BLOCKED Clean central storage-boundary canonicalization with a small diff, but it does not remove transient call-site boxing and the Android regression did not complete.
5 try-fix-2 Primary FAIL; regression skipped Fails the BooleanBoxes setter-storage assertions because default-only canonicalization does not fix explicit setter boxing. Per ranking rules, this failed candidate must remain below non-failing/unblocked candidates.

Analysis

No candidate has a fully passing Android regression result in the recorded evidence. try-fix-2 is disqualified by primary test failure. try-fix-1 and try-fix-3 both passed the targeted BooleanBoxes tests, but their mandatory Android MemoryTests were blocked by xharness instrumentation timeout, leaving them unproven. Between those alternatives, try-fix-1 is stronger for transient allocation reduction while try-fix-3 is simpler, but neither can outrank the PR path without successful regression evidence.

The raw PR fix directly addresses the observed allocation pattern by updating boolean bindable-property defaults and setters to use shared boxes. The expert reviewer found the BooleanBoxes implementation sound and identified one required non-functional correction: revert .github/workflows/review-trigger.yml from pull-requests: write to pull-requests: read. Applying that correction yields pr-plus-reviewer, which is strictly better than pr and avoids choosing an unproven central rewrite.

Winner

pr-plus-reviewer is the winning candidate. It keeps the submitted PR fix, applies the expert reviewer's actionable security feedback, and avoids adopting try-fix candidates that either failed primary tests or were blocked before completing Android regression validation.


Future Action — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jun 12, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current June 12, 2026 11:19

@kubaflo kubaflo 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.

LGTM! Could you please resolve conflicts, so that I can merge?

pictos and others added 11 commits June 13, 2026 23:03
Replace raw true/false/default(bool) literals with BooleanBoxes.TrueBox
and BooleanBoxes.FalseBox in BindableProperty.Create defaultValue arguments
across all bool-typed BindableProperties in Controls.Core. This avoids
repeated boxing allocations on every property default-value access.

Added using Microsoft.Maui.Controls.Internals; to 26 files that
did not already have it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

# Conflicts:
#	src/Controls/src/Core/SwipeView/SwipeItem.cs
…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>
@kubaflo

kubaflo commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo kubaflo merged commit 22c02a2 into dotnet:inflight/current Jun 14, 2026
4 of 21 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR9 milestone Jun 14, 2026
@pictos pictos deleted the pj/avoid-bool-boxing branch June 15, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-general General issues that span multiple controls, or common base classes such as View or Element community ✨ Community Contribution platform/android platform/ios platform/tizen Samsung Tizen Devices (TV) s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants