KEMBAR78
Optimize converters for GridLength, ColumnDefinition, and RowDefinition by symbiogenesis · Pull Request #20048 · dotnet/maui · GitHub
Skip to content

Conversation

@symbiogenesis
Copy link
Contributor

@symbiogenesis symbiogenesis commented Jan 22, 2024

Some simple optimizations to these common converters.

There were already tests around these converters here and here.

EDIT June 2025

I ran this just to check, and maybe my machine is faster (probably) or maui got better (probably), so the difference is not as great, but still better.

BenchmarkDotNet v0.13.10, macOS 15.5 (24F74) [Darwin 24.5.0]
Apple M3 Pro, 1 CPU, 12 logical and 12 physical cores
.NET SDK 9.0.105
  [Host]     : .NET 9.0.5 (9.0.525.21509), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 9.0.5 (9.0.525.21509), Arm64 RyuJIT AdvSIMD

Before this PR:

Method Mean Error StdDev Gen0 Gen1 Allocated
ColumnConvertFrom 42.71 us 0.488 us 0.407 us 35.0952 0.1831 286.72 KB
ColumnConvertTo 17.30 us 0.189 us 0.167 us 5.1575 - 42.19 KB
RowConvertFrom 42.86 us 0.201 us 0.188 us 35.0952 0.1831 286.72 KB
RowConvertTo 17.51 us 0.101 us 0.090 us 5.1575 - 42.19 KB

After this PR (and a small tweak to reduce allocations):

Method Mean Error StdDev Gen0 Gen1 Allocated
ColumnConvertFrom 38.96 us 0.382 us 0.357 us 30.3955 0.1221 248.44 KB
ColumnConvertTo 11.45 us 0.108 us 0.101 us 1.5259 - 12.5 KB
RowConvertFrom 37.37 us 0.337 us 0.299 us 30.3955 0.1831 248.44 KB
RowConvertTo 11.58 us 0.136 us 0.127 us 1.5259 - 12.5 KB

OLD NUMBERS*

Before:

Method Mean Error StdDev Gen0 Gen1 Allocated
ColumnConvertFrom 86.19 us 5.345 us 15.675 us 29.2969 0.2441 270.31 KB
ColumnConvertTo 30.46 us 0.445 us 0.395 us 4.5776 - 42.19 KB
RowConvertFrom 72.95 us 1.284 us 1.201 us 29.2969 0.2441 270.31 KB
RowConvertTo 30.67 us 0.278 us 0.260 us 4.5776 - 42.19 KB

After:

Method Mean Error StdDev Gen0 Gen1 Allocated
ColumnConvertFrom 59.00 us 1.160 us 3.157 us 25.7568 0.1221 236.72 KB
ColumnConvertTo 19.37 us 0.320 us 0.284 us 2.3804 - 21.88 KB
RowConvertFrom 58.12 us 1.113 us 1.093 us 25.7568 0.1831 236.72 KB
RowConvertTo 19.85 us 0.397 us 0.569 us 2.3804 - 21.88 KB

@symbiogenesis symbiogenesis requested a review from a team as a code owner January 22, 2024 02:15
@ghost ghost added the community ✨ Community Contribution label Jan 22, 2024
@ghost
Copy link

ghost commented Jan 22, 2024

Hey there @symbiogenesis! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@symbiogenesis symbiogenesis force-pushed the griddefinitionconverter-optimization branch 3 times, most recently from 776086d to 48d4b8b Compare January 22, 2024 08:03
@samhouts samhouts added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Jan 25, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Foda
Foda previously approved these changes Jun 5, 2024
@mattleibow mattleibow force-pushed the griddefinitionconverter-optimization branch from be5310e to 04988f9 Compare January 27, 2025 20:49
@StephaneDelcroix
Copy link
Contributor

note that these converters probably aren't used in Release mode with XamlC enabled

@mattleibow
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

note that these converters probably aren't used in Release mode with XamlC enabled

Will this help with hot reload scenarios? They run when that is happening?

@mattleibow
Copy link
Member

mattleibow commented Jun 11, 2025

moved to description.

@mattleibow mattleibow added layout-grid perf/memory-leak 💦 Memory usage grows / objects live forever (sub: perf) perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) labels Jun 11, 2025
@mattleibow
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

mattleibow
mattleibow previously approved these changes Jun 12, 2025
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix left a comment

Choose a reason for hiding this comment

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

when all test passes, it's ok for me

public const ushort StyleLocal = 0x100;

public static readonly SetterSpecificity DefaultValue = new SetterSpecificity(0);
public static readonly SetterSpecificity LowestAppliedValue = new SetterSpecificity(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I missing something or is this not used anywhere? Perhaps some leftover of a rebase?

@PureWeen PureWeen changed the base branch from main to inflight/current June 13, 2025 12:06
@PureWeen PureWeen changed the base branch from inflight/current to main June 13, 2025 12:06
@PureWeen PureWeen dismissed stale reviews from StephaneDelcroix and mattleibow June 13, 2025 12:06

The base branch was changed.

@PureWeen PureWeen changed the base branch from main to inflight/current June 13, 2025 17:11
@PureWeen PureWeen merged commit ce83b4c into dotnet:inflight/current Jun 13, 2025
130 of 131 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 16, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen pushed a commit that referenced this pull request Jun 21, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen pushed a commit that referenced this pull request Jun 25, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen pushed a commit that referenced this pull request Jun 25, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
github-actions bot pushed a commit that referenced this pull request Jun 26, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
github-actions bot pushed a commit that referenced this pull request Jun 26, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
github-actions bot pushed a commit that referenced this pull request Jun 27, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen pushed a commit that referenced this pull request Jun 27, 2025
…on (#20048)

* add benchmarks

* set CanConvertTo to be consistent with the ColumnDefinitionTypeConverter

* optimize GridLength conversion

* optimize grid definition conversion

* enable nullable types

* fix build

* reduce diff

* Slightly better

* Update RowDefinition.cs

* Even better

---------

Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
PureWeen added a commit that referenced this pull request Jun 28, 2025
For more information about inflight process check
https://github.com/dotnet/maui/wiki/Inflight-Branch-Process

# .NET MAUI Release Notes - Inflight/Candidate Branch

## What's Changed

### MAUI Product Fixes
* [iOS] CarouselView with CarouselViewHandler2 make app crash when
Loop="False" and user scroll to the last position - fixes #26863 by
@kubaflo in #26868
* Fixes Setting BackgroundColor to null does not actually changes
BackgroundColor - fixes #22914 and #19576 by @jgonzalez-gft in
#22917
* Fixed the picker title's color - fixes #16737 by @kubaflo in
#23075
* [android] Fallback to default icons in SearchHandler by @aheubusch in
#25067
* ScrollView's Background on iOS - fixes #24016 by @kubaflo in
#25541
* [iOS] Enabled MultiTouch Support for Handling Multi-Touch Points in
GraphicsView - fixes #29461 by @prakashKannanSf3972 in
#29895
* Optimize converters for GridLength, ColumnDefinition, and
RowDefinition - performance improvement by @emiller in
#20048
* Add defensive IsAlive check to Android ViewExtensions.OnUnloaded -
fixes #28051 by @jfversluis in #29934
* [Windows] Fixed runtime update issue for SearchBar PlaceholderColor
and BackgroundColor - fixes #29962 by @Tamilarasan-Paranthaman in
#29965
* Weak subscription to CanExecuteChange events - fixes #16124 by
@sneumaier in #29837
* [iOS, Mac] Fix for downsized image retaining original dimensions in
GraphicsView - fixes #30006 by @SyedAbdulAzeemSF4852 in
#30007
* [Android] Prevent Picker from Gaining Focus on Touch - fixes #19739,
#8546, #13503, #24862, #28121, #21704, #15394 by @bhavanesh2001 in
#29068
* Fix CV1 GridItemsLayout centering single item AND Fix Empty view not
resizing when bounds change - fixes #29595, #29634 by @albyrock87 in
#29639

### Testing
* [Testing] Feature Matrix UITest Cases for Button by @TamilarasanSF4853
in #29803
* [Testing] Feature matrix UITest Cases for BoxView Control by
@HarishKumarSF4517 in #29808
* [Testing] Enable HandlerDoesNotLeak for Button and ProgressBar by
@bhavanesh2001 in #29896
* [Testing] Add Validation Test For Issue28051 On Android by
@prakashKannanSf3972 in #30026
* [Testing] Fixed Test case failure in PR 30115 - [2025/06/23] Candidate
by @HarishKumarSF4517 in #30136

### Dependency Updates
* Bump to 1.7.250606001 of WindowsAppSDK by @sneumaier in
#29915

### Housekeeping
* [housekeeping] Update namespaces in HostApp and Shared tests projects
by @bhavanesh2001 in #29904
* Update SetterSpecificity.cs Remove Extra Line From Bad Merge by
@sneumaier in #29987
* Revert - Fixed the Label not sized correctly on Android by @Ahamed-Ali
in #30023
* Revert "Fixes Setting BackgroundColor to null does not actually
changes BackgroundColor #22914 (#22917)" by @mattleibow in
#30031
* [create-pull-request] automated change by @github-actions[bot] in
#30019
* [create-pull-request] automated change by @github-actions[bot] in
#30043
* [create-pull-request] automated change by @github-actions[bot] in
#30078
* Update Controls.TestCases.HostApp.csproj by @HarishKumarSF4517 in
#30124

## New Contributors
* @albyrock87 made their first contribution in
#29639
* @SyedAbdulAzeemSF4852 made their first contribution in
#30007
* @emiller made their first contribution in
#20048
* @jgonzalez-gft made their first contribution in
#22917
* @aheubusch made their first contribution in
#25067

**Full Changelog**:
https://github.com/dotnet/maui/compare/main..inflight/candidate
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution layout-grid perf/general The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) perf/memory-leak 💦 Memory usage grows / objects live forever (sub: perf)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants