forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Add benchmark for source-generated SetBinding #25
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
simonrozsival
merged 9 commits into
binding-source-generator
from
source-generated-binding-benchmarker
Apr 23, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e10ee07
Add benchmark for source-generated SetBinding
simonrozsival dcacb6c
Auto-format source code
67838d0
improve overload diagnostics tests
jkurdek 122e42f
added more complex overload tests
jkurdek 8248cc2
improve predicate method filtering
jkurdek 03722c6
improved diagnostics on overload detection
jkurdek 996ce09
Auto-format source code
6695a32
add ArgumentOutOfRangeException
jkurdek 53bc879
Auto-format source code
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
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
71 changes: 71 additions & 0 deletions
71
src/Core/tests/Benchmarks/Benchmarks/SourceGeneratedBindingBenchmarker.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,71 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using BenchmarkDotNet.Attributes; | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Internals; | ||
|
|
||
| namespace Microsoft.Maui.Benchmarks | ||
| { | ||
| [MemoryDiagnoser] | ||
| public class SourceGeneratedBindingBenchmarker | ||
| { | ||
| // Avoids the warning: | ||
| // The minimum observed iteration time is 10.1000 us which is very small. It's recommended to increase it to at least 100.0000 ms using more operations. | ||
| const int Iterations = 10; | ||
|
|
||
| public class MyObject : BindableObject | ||
| { | ||
| public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(MyObject)); | ||
|
|
||
| public string Name | ||
| { | ||
| get { return (string)GetValue(NameProperty); } | ||
| set { SetValue(NameProperty, value); } | ||
| } | ||
|
|
||
| public MyObject? Child { get; set; } | ||
|
|
||
| public List<MyObject> Children { get; private set; } = new List<MyObject>(); | ||
| } | ||
|
|
||
| readonly MyObject Source = new() | ||
| { | ||
| Name = "A", | ||
| Child = new() { Name = "A.Child" }, | ||
| Children = | ||
| { | ||
| new() { Name = "A.Children[0]" }, | ||
| new() { Name = "A.Children[1]" }, | ||
| } | ||
| }; | ||
| readonly MyObject Target = new() { Name = "B" }; | ||
|
|
||
| [Benchmark] | ||
| public void SourceGeneratedBindName() | ||
| { | ||
| for (int i = 0; i < Iterations; i++) | ||
| { | ||
| Target.SetBinding(MyObject.NameProperty, static (MyObject o) => o.Name, source: Source, mode: BindingMode.OneWay); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void SourceGeneratedBindChild() | ||
| { | ||
| for (int i = 0; i < Iterations; i++) | ||
| { | ||
| Target.SetBinding(MyObject.NameProperty, static (MyObject o) => o.Child?.Name, source: Source, mode: BindingMode.OneWay); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void SourceGeneratedBindChildIndexer() | ||
| { | ||
| for (int i = 0; i < Iterations; i++) | ||
| { | ||
| Target.SetBinding(MyObject.NameProperty, static (MyObject o) => o.Children[0].Name, source: Source, mode: BindingMode.OneWay); | ||
| } | ||
| } | ||
| } | ||
| } |
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.
I see that we do the validation of the number of arguments in
IsSetBindingMethodbut it's still making me a little uneasy to just reach for an index without a check for the length of the array in the same scope. This could break if somebody refactors this code later. I'd just addArgumentOutOfRangeException.ThrowIfLessThan(argumentList, 2);