Optimize conversion of MouseGesture from/to string, reduce allocations #10265
+175
−189
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
MouseGesture
and its conversion from/to string. Also adds documentation for whole class.I've additionally removed the duplicated functionality in
MouseGesture
to check forMouseAction
validity.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
MouseAction
andModifierKeys
are no longer retrieved viaTypeDescriptor.GetConverter
but rather used statically, which is aligned with howKeyGestureConverter
and 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
MouseGesture
if you wish to influence the output for this type directly.