Optimize conversion of ModifierKeys enum from/to string, reduce allocations#9683
Merged
Conversation
harshit7962
previously approved these changes
Jan 3, 2025
Member
There was a problem hiding this comment.
@h3xds1nz, the PR can be taken in after resolution of the conflict.
Member
|
Also, as we already have |
Member
Author
|
@harshit7962 I didn't PR any as there are tests in #8215, same for KeyConverter. I've unfortunately found out after I wrote them myself, haha. On my way with the conflicts. |
70cb919 to
c8faea9
Compare
harshit7962
approved these changes
Jan 3, 2025
Member
harshit7962
left a comment
There was a problem hiding this comment.
Reapproving post resolution of conflict.
Member
|
Thanks for the contribution @h3xds1nz. |
Member
Author
|
@harshit7962 Thanks for taking it :) |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #7502
Description
Parsing optimization for
ModifierKeysand its conversion from/to string. Conversion from is now alloc-free, conversion to is either free or reduced by a big margin (see benchmarks).ConvertFromis now fully flying onReadOnlySpan<char>instead of multiple substrings and trims on string instances.ConvertTois now within 2 procs, fast-path and slow-path. The only allocated string instance is with multiple modifiers.ConvertTowill now be interned with the rest since we useStringComparison.OrdinalIgnoreCase.ModifierKeysFlagstatic field is now a compile-time constant, saving memory and providing speed-up.ConvertFromBenchmark for all possible modifiersConvertTobenchmark for different scenariosCustomer Impact
Increased performance, zero/reduced allocations, less static memory.
Regression
No.
Testing
Local build, CI, assert tests:
Risk
Low.
Microsoft Reviewers: Open in CodeFlow