-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize GetVisualTreeElementsWindowsInternal (#19984)
* add benchmark * prevent multiple enumerations --------- Co-authored-by: Edward Miller <symbiogenisis@outlook.com>
- Loading branch information
1 parent
0e61f5e
commit 49be7e3
Showing
2 changed files
with
69 additions
and
7 deletions.
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
49 changes: 49 additions & 0 deletions
49
src/Core/tests/Benchmarks/Benchmarks/VisualTreeBenchmarker.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Microsoft.Maui.Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class VisualTreeBenchmarker | ||
{ | ||
static readonly View[] Views = [ | ||
new Border(), new BoxView(), new CarouselView(), new Grid(), new Entry(), new Picker(), new CollectionView(), | ||
new CheckBox(), new DatePicker(), new Stepper(), new Slider(), new ActivityIndicator(), new Frame(), | ||
new ContentView(), new ProgressBar(), new SearchBar(), new Switch(), new TimePicker(), new WebView(), new Button(), | ||
]; | ||
|
||
private const int Iterations = 100; | ||
|
||
[Benchmark] | ||
public void GetVisualTreeElements() | ||
{ | ||
var layout = new VerticalStackLayout(); | ||
|
||
for (int i = 0; i < Iterations; i++) | ||
{ | ||
var childLayout = new VerticalStackLayout(); | ||
|
||
foreach (var view in Views) | ||
{ | ||
childLayout.Add(view); | ||
|
||
var grandchildLayout = new VerticalStackLayout(); | ||
|
||
foreach (var view2 in Views) | ||
{ | ||
grandchildLayout.Add(view); | ||
grandchildLayout.GetVisualTreeElements(grandchildLayout.Frame); | ||
} | ||
|
||
layout.Add(grandchildLayout); | ||
|
||
childLayout.GetVisualTreeElements(childLayout.Frame); | ||
} | ||
|
||
layout.Add(childLayout); | ||
|
||
layout.GetVisualTreeElements(layout.Frame); | ||
} | ||
} | ||
} | ||
} |