You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing optimization for MouseGesture and its conversion from/to string. Also adds documentation for whole class.
I've additionally removed the duplicated functionality in MouseGesture to check for MouseAction validity.
ConvertFrom Benchmarks
Method
source
Mean [ns]
Error [ns]
StdDev [ns]
Gen0
Allocated [B]
Original
Ctr(...)ick [29]
238.962 ns
3.9509 ns
3.6956 ns
0.0238
400 B
PR__EDIT
Ctr(...)ick [29]
30.909 ns
0.3631 ns
0.3396 ns
0.0019
32 B
Original
Ctrl (...)Click [31]
271.305 ns
3.0945 ns
2.7432 ns
0.0310
520 B
PR__EDIT
Ctrl (...)Click [30]
38.710 ns
0.4011 ns
0.3556 ns
0.0019
32 B
Original
Ctrl+LeftClick
203.858 ns
1.2445 ns
1.1641 ns
0.0119
200 B
PR__EDIT
Ctrl+LeftClick
16.343 ns
0.1529 ns
0.1430 ns
0.0019
32 B
Original
LeftClick
100.071 ns
0.4549 ns
0.4033 ns
0.0057
96 B
PR__EDIT
LeftClick
9.861 ns
0.1375 ns
0.1219 ns
0.0019
32 B
[Benchmark][Arguments("Ctrl + Alt + MiddleDoubleClick")][Arguments(" Ctrl + MiddleDoubleClick ")][Arguments("Ctrl+LeftClick")][Arguments("LeftClick")]publicMouseGestureOriginal(objectsource){return(MouseGesture)oldMouseGestureConverter.ConvertFrom(null,null,source);}
There is a behavioral change related to the fact that type converters of MouseAction and ModifierKeys are no longer retrieved via TypeDescriptor.GetConverter but rather used statically, which is aligned with how KeyGestureConverter and most of other converters using other types that have converters are implemented. This provides around 80-90% of the performance benefit, allows use of ReadOnlySpan<char> to pass slices to the converter methods (as you cannot box it in object), etc.
I haven't found any evidence of people registering custom type converters for those enums, needless to say that you may just register one for MouseGesture if you wish to influence the output for this type directly.
There is a behavioral change related to the fact that type converters of MouseAction and ModifierKeys are no longer retrieved via TypeDescriptor.GetConverter but rather used statically, which is aligned with how KeyGestureConverter and most of other converters using other types that have converters are implemented. This provides around 80-90% of the performance benefit, allows use of ReadOnlySpan<char> to pass slices to the converter methods (as you cannot box it in object), etc.
Would it be possible to keep the existing behavior by first checking that the type converters registered for MouseAction and ModifierKeys is the default one ? You could then call the normal methods when there's a custom type converter and call the span methods when it's the default type converter. It would be a bit slower due to the fact that we need to check the registered type converters but at least this change wouldn't be potentially breaking.
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
Community ContributionA label for all community ContributionsPRmetadata: Label to tag PRs, to facilitate with triage
2 participants
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.
Description
Parsing optimization for
MouseGestureand its conversion from/to string. Also adds documentation for whole class.I've additionally removed the duplicated functionality in
MouseGestureto check forMouseActionvalidity.ConvertFrom Benchmarks
ConvertTo Benchmarks
Customer Impact
Increased performance, decreased allocations.
Regression
No.
Testing
Local build, backed with #10263.
Risk
Low, changes have been tested extensively.
There is a behavioral change related to the fact that type converters of
MouseActionandModifierKeysare no longer retrieved viaTypeDescriptor.GetConverterbut rather used statically, which is aligned with howKeyGestureConverterand most of other converters using other types that have converters are implemented. This provides around 80-90% of the performance benefit, allows use ofReadOnlySpan<char>to pass slices to the converter methods (as you cannot box it inobject), etc.I haven't found any evidence of people registering custom type converters for those enums, needless to say that you may just register one for
MouseGestureif you wish to influence the output for this type directly.