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
[WinUI] Perf when creating non-trivial grids (and other visual controls) (take 2) #22108
Draft
MartyIX
wants to merge
6
commits into
dotnet:main
Choose a base branch
from
MartyIX:feature/2024-04-28-WinUI-IsPlatformViewNew
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,6 +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_Clicked"/> | ||
|
||
<HorizontalStackLayout x:Name="myGridWrapper"> | ||
<Grid x:Name="contentGrid"/> | ||
</HorizontalStackLayout> | ||
</VerticalStackLayout> | ||
</ContentPage> |
68 changes: 60 additions & 8 deletions
68
src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
This file contains 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,18 +1,70 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Maui.Controls.Sample | ||
namespace Maui.Controls.Sample; | ||
|
||
public partial class MainPage : ContentPage | ||
{ | ||
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) | ||
{ | ||
public MainPage() | ||
Stopwatch sw = Stopwatch.StartNew(); | ||
contentGrid.Clear(); | ||
|
||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) | ||
{ | ||
InitializeComponent(); | ||
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) | ||
{ | ||
Label label = new Label() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
contentGrid.Add(label, column: columnIndex, row: rowIndex); | ||
} | ||
} | ||
|
||
sw.Stop(); | ||
info.Text = $"Clearing grid took: {sw.ElapsedMilliseconds} ms"; | ||
} | ||
|
||
private void BatchGenerate_Clicked(object sender, EventArgs e) | ||
{ | ||
Stopwatch sw = Stopwatch.StartNew(); | ||
|
||
int batchSize = int.Parse(BatchSize.Text); | ||
|
||
for (int i = 0; i < batchSize; i++) | ||
{ | ||
contentGrid.Clear(); | ||
|
||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) | ||
{ | ||
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) | ||
{ | ||
Label label = new Label() { Text = $"[{columnIndex}x{rowIndex}]" }; | ||
contentGrid.Add(label, column: columnIndex, row: rowIndex); | ||
} | ||
} | ||
} | ||
|
||
sw.Stop(); | ||
info.Text = $"Grid was created {batchSize} times and it took {sw.ElapsedMilliseconds} ms in total. Avg run took {Math.Round(sw.ElapsedMilliseconds / (double)batchSize, 2)} ms"; | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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
internal
if 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
internal
if it is a property onIElement
.Is there a way this could detect if
Handler
wasnull
and became non-null
for the first time? Then maybe we wouldn't need a newbool
property?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
IsPlatformViewNew
totrue
and then back tofalse
:IView.IsPlatformViewNew
totrue
.IView.IsPlatformViewNew
tofalse
.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.IsPlatformViewNew
flag 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.IsPlatformViewNew
but rather add two new mapper calls:but I would still need to store the state somewhere and mappers are "state-less" AFAIK.