-
Notifications
You must be signed in to change notification settings - Fork 2k
[WinUI] Perf when creating non-trivial grids (and other visual controls) (take 2) #22108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MartyIX
wants to merge
17
commits into
dotnet:main
from
MartyIX:feature/2024-04-28-WinUI-IsPlatformViewNew
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4512242
Add batch generate
MartyIX 8272356
Add batch generate
MartyIX 9d2c947
WIP: Add IsPlatformViewNew
MartyIX 8951247
FontSize
MartyIX 1c29513
AccessibilityExtensions
MartyIX 49353da
Fix stubs
MartyIX 87600f8
...
MartyIX 5f8f148
Generate grid
MartyIX acf2c4f
Improve
MartyIX e5ac68b
Improve
MartyIX e2c79b7
improve
MartyIX b9392b8
Improve
MartyIX 10a19fb
Improve
MartyIX b4d9d43
Improve test code
MartyIX d9274a7
Grid bulk experiment (row level)
MartyIX a3bc00f
AccessibilityExtensions: Improve
MartyIX f7bfa48
Grid bulk experiment (row level) (2)
MartyIX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,18 @@ | ||
| <ContentPage | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:local="clr-namespace:Maui.Controls.Sample" | ||
| x:Class="Maui.Controls.Sample.MainPage" | ||
| xmlns:local="clr-namespace:Maui.Controls.Sample"> | ||
| x:DataType="local:MainPage"> | ||
| <VerticalStackLayout x:Name="myLayout"> | ||
| <Label x:Name="info" Text="Click a button" VerticalOptions="Center"/> | ||
| <Button Text="Clear Grid" Clicked="ClearGrid_Clicked"/> | ||
| <Button Text="Generate Grid" Clicked="Button_Clicked"/> | ||
| <Entry x:Name="BatchSize" Text="15"/> | ||
| <Button Text="Batch Generate Grid" Clicked="BatchGenerate_ClickedAsync"/> | ||
|
|
||
| <HorizontalStackLayout x:Name="myGridWrapper"> | ||
| <Grid x:Name="contentGrid"/> | ||
| </HorizontalStackLayout> | ||
| </VerticalStackLayout> | ||
| </ContentPage> |
102 changes: 100 additions & 2 deletions
102
src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,107 @@ | ||
| namespace Maui.Controls.Sample; | ||
| using System; | ||
| using System.Diagnostics; | ||
| using Microsoft.Maui.Controls; | ||
|
|
||
| namespace Maui.Controls.Sample; | ||
|
|
||
| public partial class MainPage : ContentPage | ||
| { | ||
| const int rowCount = 30; | ||
| const int columnCount = 30; | ||
|
|
||
| public MainPage() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } | ||
|
|
||
| private void ClearGrid_Clicked(object sender, EventArgs e) | ||
| { | ||
| Stopwatch sw = Stopwatch.StartNew(); | ||
|
|
||
| contentGrid.Clear(); | ||
|
|
||
| sw.Stop(); | ||
|
|
||
| info.Text = $"Clearing grid took: {sw.ElapsedMilliseconds} ms"; | ||
| } | ||
|
|
||
| private void Button_Clicked(object sender, EventArgs e) | ||
| { | ||
| Stopwatch sw = Stopwatch.StartNew(); | ||
| contentGrid.Clear(); | ||
|
|
||
| for (int n = 0; n < rowCount; n++) | ||
| { | ||
| contentGrid.RowDefinitions.Add(new RowDefinition()); | ||
| } | ||
|
|
||
| for (int n = 0; n < columnCount; n++) | ||
| { | ||
| contentGrid.ColumnDefinitions.Add(new ColumnDefinition()); | ||
| } | ||
|
|
||
| int i = 0; | ||
| Label[] views = new Label[rowCount * columnCount]; | ||
|
|
||
| for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) | ||
| { | ||
|
|
||
| for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) | ||
| { | ||
| Label view = new Label() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
| // Button view = new() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
| // contentGrid.Add(view, column: columnIndex, row: rowIndex); | ||
|
|
||
| views[i] = view; | ||
| i++; | ||
|
|
||
| contentGrid.SetRow(view, rowIndex); | ||
| contentGrid.SetRowSpan(view, 1); | ||
|
|
||
| contentGrid.SetColumn(view, columnIndex); | ||
| contentGrid.SetColumnSpan(view, 1); | ||
| } | ||
| } | ||
|
|
||
| contentGrid.AddBulk(views); | ||
|
|
||
| sw.Stop(); | ||
| info.Text = $"Grid was created in: {sw.ElapsedMilliseconds} ms"; | ||
| } | ||
|
|
||
| private async void BatchGenerate_ClickedAsync(object sender, EventArgs e) | ||
| { | ||
| Stopwatch sw = Stopwatch.StartNew(); | ||
|
|
||
| long sumMs = 0; | ||
| int batchSize = int.Parse(BatchSize.Text); | ||
|
|
||
| for (int i = 0; i < batchSize; i++) | ||
| { | ||
| sw.Reset(); | ||
| sw.Start(); | ||
|
|
||
| contentGrid.Clear(); | ||
|
|
||
| for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) | ||
| { | ||
| for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) | ||
| { | ||
| Label view = new() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
| //Button view = new() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
| contentGrid.Add(view, column: columnIndex, row: rowIndex); | ||
| } | ||
| } | ||
|
|
||
| sw.Stop(); | ||
| sumMs += sw.ElapsedMilliseconds; | ||
|
|
||
| int runs = i + 1; | ||
|
|
||
| info.Text = $"Grid was created {runs} times and it took {sumMs} ms in total. Avg run took {Math.Round(sumMs / (double)runs, 2)} ms"; | ||
|
|
||
| await Task.Delay(1000).ConfigureAwait(true); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is terrible. It should be
internalif possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a way to make this
internalif it is a property onIElement.Is there a way this could detect if
Handlerwasnulland became non-nullfor the first time? Then maybe we wouldn't need a newboolproperty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I can simulate it that way because I need to set
IsPlatformViewNewtotrueand then back tofalse:IView.IsPlatformViewNewtotrue.IView.IsPlatformViewNewtofalse.an alternative which I would consider the best (in an ideal world) would be to pass a flag to:
maui/src/Core/src/Handlers/Element/ElementHandler.cs
Line 79 in e33d176
but unfortunately then I would need to propagate that flag here:
maui/src/Core/src/PropertyMapper.cs
Line 47 in e33d176
and that would mean changing the way mappers are defined:
maui/src/Core/src/PropertyMapper.cs
Line 18 in e33d176
which seems like a very invasive thing to do (with many and many changes required). That's why I went with the
IView.IsPlatformViewNewflag to avoid making changes to mappers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this a bit more and one alternative idea would be: Do not add
Element.IsPlatformViewNewbut rather add two new mapper calls:but I would still need to store the state somewhere and mappers are "state-less" AFAIK.