-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Get rid of s_compatOids in favor of a switch #120697
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
Conversation
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.
Pull Request Overview
This PR optimizes the OID lookup mechanism by replacing a static dictionary s_compatOids
with a switch expression. The change eliminates the overhead of creating an 11-item dictionary during static construction, which was rarely accessed, in favor of a more efficient compile-time optimized switch statement.
- Replaces dictionary lookup with switch expression for better performance
- Removes static dictionary initialization overhead
- Maintains identical functionality with cleaner code structure
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidLookup.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/OidLookup.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
Unrelated to this PR: we have quite a few Or just replace them all manually at least in the BCL cc @jkotas |
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.
This not only removes the pretty slow static init, but also makes lookup faster: sharplab (trie)
There is definitely more I think we can do in this OidLookup, I will keep chipping away at it. |
Only in some cases. Others will fall back to a binary search still based on computing a hash code, e.g SharpLab switch also only works for the equivalent of StringComparer.Ordinal. |
s_compatOids
is a dictionary that is never updated at runtime and has contained 11 items for more than 5 years.Rather than use a dictionary, let's use a switch here. The compiler will generate an efficient lookup for the handful of switch cases. This means we are doing less work in the .cctor of
OidLookup
to create the dictionary. This dictionary is not frequently read from, either, so the eagerly created dictionary was wasted work, most of the time.