-
Notifications
You must be signed in to change notification settings - Fork 2k
Optimize resetting gesture recognizers #19987
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cea6f70
reduce LINQ usage
0a0fc53
Remove useless check that will always be false
cc9c544
use HashSet
2381637
reduce enumerations and casting
b0f2c4f
reduce LINQ usage
eb4eac8
only cast once
7cd4832
add benchmarks
8012720
fix build
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
123 changes: 123 additions & 0 deletions
123
src/Core/tests/Benchmarks/Benchmarks/GestureRecognizerBenchmarker.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 |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using Microsoft.Maui.Controls; | ||
|
|
||
| namespace Microsoft.Maui.Handlers.Benchmarks; | ||
|
|
||
| [MemoryDiagnoser] | ||
| public class GestureRecognizerBenchmarker | ||
| { | ||
| View[] _views = null; | ||
| IGestureRecognizer[] _gestureRecognizers = null; | ||
|
|
||
| [GlobalSetup] | ||
| public void Setup() | ||
| { | ||
| _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(), | ||
| ]; | ||
|
|
||
| _gestureRecognizers = [ | ||
| new PointerGestureRecognizer(), new TapGestureRecognizer(), new PanGestureRecognizer(), | ||
| new SwipeGestureRecognizer(), new DragGestureRecognizer(), new DropGestureRecognizer(), | ||
| ]; | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void AddLotsOfGestureRecognizers() | ||
| { | ||
| var layout = new VerticalStackLayout(); | ||
|
|
||
| AddGestureRecognizers(layout, _gestureRecognizers); | ||
|
|
||
| for (int i = 0; i < 100; i++) | ||
| { | ||
| var childLayout = new VerticalStackLayout(); | ||
|
|
||
| AddGestureRecognizers(childLayout, _gestureRecognizers); | ||
|
|
||
| foreach (var view in _views) | ||
| { | ||
| AddGestureRecognizers(view, _gestureRecognizers); | ||
|
|
||
| childLayout.Add(view); | ||
| } | ||
|
|
||
| layout.Add(childLayout); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| [Benchmark] | ||
| public void ClearLotsOfGestureRecognizers() | ||
| { | ||
| var layout = new VerticalStackLayout(); | ||
|
|
||
| for (int i = 0; i < 1000; i++) | ||
| { | ||
| AddGestureRecognizers(layout, _gestureRecognizers); | ||
| } | ||
|
|
||
| layout.GestureRecognizers.Clear(); | ||
| } | ||
|
|
||
|
|
||
| [Benchmark] | ||
| public void RemoveLotsOfGestureRecognizers() | ||
| { | ||
| var layout = new VerticalStackLayout(); | ||
|
|
||
| foreach (var gestureRecognizer in _gestureRecognizers) | ||
| { | ||
| for (int i = 0; i < 1000; i++) | ||
| { | ||
| layout.GestureRecognizers.Remove(gestureRecognizer); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void AddOneGestureRecognizer() | ||
| { | ||
| var gestureRecognizer = new PointerGestureRecognizer(); | ||
|
|
||
| for (int i = 0; i < 1000; i++) | ||
| { | ||
| var button = new Button(); | ||
| button.GestureRecognizers.Add(gestureRecognizer); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void RemoveOneGestureRecognizer() | ||
| { | ||
| var gestureRecognizer = new PointerGestureRecognizer(); | ||
|
|
||
| for (int i = 0; i < 1000; i++) | ||
| { | ||
| var button = new Button(); | ||
| button.GestureRecognizers.Remove(gestureRecognizer); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void ClearOneGestureRecognizer() | ||
| { | ||
| for (int i = 0; i < 1000; i++) | ||
| { | ||
| var button = new Button(); | ||
| var gestureRecognizer = new PointerGestureRecognizer(); | ||
| button.GestureRecognizers.Add(gestureRecognizer); | ||
| button.GestureRecognizers.Clear(); | ||
| } | ||
| } | ||
|
|
||
| private static void AddGestureRecognizers(View view, params IGestureRecognizer[] gestureRecognizers) | ||
| { | ||
| foreach (var gestureRecognizer in gestureRecognizers) | ||
| { | ||
| view.GestureRecognizers.Add(gestureRecognizer); | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.