Skip to content
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

Use FrozenSet in two appropriate places #2640

Merged
merged 2 commits into from
Jun 17, 2024
Merged

Conversation

joegoldman2
Copy link
Contributor

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • If any gains or losses in performance are possible, you've included benchmarks for your changes. More info
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Description

Convert two static HashSet on which only read operations are performed to FrozenSet.

Benchmark result:

Method Mean Error StdDev
HashSetContains 9.388 ns 0.1441 ns 0.1348 ns
FrozenSetContains 6.786 ns 0.1620 ns 0.1515 ns
Benchmark code
using System.Collections.Frozen;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkRunner.Run<Tests>();

public class Tests
{
    public static HashSet<string> OpenIdProviderMetadataNamesUpperCase = new HashSet<string>
    {
        "ACR_VALUES_SUPPORTED",
        "AUTHORIZATION_ENDPOINT",
        "AUTHORIZATION_RESPONSE_ISS_PARAMETER_SUPPORTED",
        "BACKCHANNEL_AUTHENTICATION_ENDPOINT",
        "BACKCHANNEL_AUTHENTICATION_REQUEST_SIGNING_ALG_VALUES_SUPPORTED",
        "BACKCHANNEL_TOKEN_DELIVERY_MODES_SUPPORTED",
        "BACKCHANNEL_USER_CODE_PARAMETER_SUPPORTED",
        "CHECK_SESSION_IFRAME",
        "CLAIMS_LOCALES_SUPPORTED",
        "CLAIMS_PARAMETER_SUPPORTED",
        "CLAIMS_SUPPORTED",
        "CLAIM_TYPES_SUPPORTED",
        "CODE_CHALLENGE_METHODS_SUPPORTED",
        ".WELL-KNOWN/OPENID-CONFIGURATION",
        "DEVICE_AUTHORIZATION_ENDPOINT",
        "DISPLAY_VALUES_SUPPORTED",
        "DPOP_SIGNING_ALG_VALUES_SUPPORTED",
        "END_SESSION_ENDPOINT",
        "FRONTCHANNEL_LOGOUT_SESSION_SUPPORTED",
        "FRONTCHANNEL_LOGOUT_SUPPORTED",
        "HTTP_LOGOUT_SUPPORTED",
        "GRANT_TYPES_SUPPORTED",
        "ID_TOKEN_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "ID_TOKEN_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED",
        "INTROSPECTION_ENDPOINT",
        "INTROSPECTION_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "INTROSPECTION_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "JWKS_URI",
        "ISSUER",
        "LOGOUT_SESSION_SUPPORTED",
        "OP_POLICY_URI",
        "OP_TOS_URI",
        "PROMPT_VALUES_SUPPORTED",
        "PUSHED_AUTHORIZATION_REQUEST_ENDPOINT",
        "REGISTRATION_ENDPOINT",
        "REQUEST_OBJECT_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "REQUEST_OBJECT_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "REQUEST_OBJECT_SIGNING_ALG_VALUES_SUPPORTED",
        "REQUEST_PARAMETER_SUPPORTED",
        "REQUEST_URI_PARAMETER_SUPPORTED",
        "REQUIRE_PUSHED_AUTHORIZATION_REQUESTS",
        "REQUIRE_REQUEST_URI_REGISTRATION",
        "RESPONSE_MODES_SUPPORTED",
        "RESPONSE_TYPES_SUPPORTED",
        "REVOCATION_ENDPOINT",
        "REVOCATION_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "REVOCATION_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "SERVICE_DOCUMENTATION",
        "SCOPES_SUPPORTED",
        "SUBJECT_TYPES_SUPPORTED",
        "TOKEN_ENDPOINT",
        "TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "TOKEN_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "UI_LOCALES_SUPPORTED",
        "USERINFO_ENDPOINT",
        "USERINFO_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "USERINFO_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "USERINFO_SIGNING_ALG_VALUES_SUPPORTED",
    };

    public static readonly FrozenSet<string> OpenIdProviderMetadataNamesUpperCaseFrozenSet = new HashSet<string>
    {
        "ACR_VALUES_SUPPORTED",
        "AUTHORIZATION_ENDPOINT",
        "AUTHORIZATION_RESPONSE_ISS_PARAMETER_SUPPORTED",
        "BACKCHANNEL_AUTHENTICATION_ENDPOINT",
        "BACKCHANNEL_AUTHENTICATION_REQUEST_SIGNING_ALG_VALUES_SUPPORTED",
        "BACKCHANNEL_TOKEN_DELIVERY_MODES_SUPPORTED",
        "BACKCHANNEL_USER_CODE_PARAMETER_SUPPORTED",
        "CHECK_SESSION_IFRAME",
        "CLAIMS_LOCALES_SUPPORTED",
        "CLAIMS_PARAMETER_SUPPORTED",
        "CLAIMS_SUPPORTED",
        "CLAIM_TYPES_SUPPORTED",
        "CODE_CHALLENGE_METHODS_SUPPORTED",
        ".WELL-KNOWN/OPENID-CONFIGURATION",
        "DEVICE_AUTHORIZATION_ENDPOINT",
        "DISPLAY_VALUES_SUPPORTED",
        "DPOP_SIGNING_ALG_VALUES_SUPPORTED",
        "END_SESSION_ENDPOINT",
        "FRONTCHANNEL_LOGOUT_SESSION_SUPPORTED",
        "FRONTCHANNEL_LOGOUT_SUPPORTED",
        "HTTP_LOGOUT_SUPPORTED",
        "GRANT_TYPES_SUPPORTED",
        "ID_TOKEN_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "ID_TOKEN_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED",
        "INTROSPECTION_ENDPOINT",
        "INTROSPECTION_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "INTROSPECTION_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "JWKS_URI",
        "ISSUER",
        "LOGOUT_SESSION_SUPPORTED",
        "OP_POLICY_URI",
        "OP_TOS_URI",
        "PROMPT_VALUES_SUPPORTED",
        "PUSHED_AUTHORIZATION_REQUEST_ENDPOINT",
        "REGISTRATION_ENDPOINT",
        "REQUEST_OBJECT_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "REQUEST_OBJECT_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "REQUEST_OBJECT_SIGNING_ALG_VALUES_SUPPORTED",
        "REQUEST_PARAMETER_SUPPORTED",
        "REQUEST_URI_PARAMETER_SUPPORTED",
        "REQUIRE_PUSHED_AUTHORIZATION_REQUESTS",
        "REQUIRE_REQUEST_URI_REGISTRATION",
        "RESPONSE_MODES_SUPPORTED",
        "RESPONSE_TYPES_SUPPORTED",
        "REVOCATION_ENDPOINT",
        "REVOCATION_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "REVOCATION_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "SERVICE_DOCUMENTATION",
        "SCOPES_SUPPORTED",
        "SUBJECT_TYPES_SUPPORTED",
        "TOKEN_ENDPOINT",
        "TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED",
        "TOKEN_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED",
        "UI_LOCALES_SUPPORTED",
        "USERINFO_ENDPOINT",
        "USERINFO_ENCRYPTION_ALG_VALUES_SUPPORTED",
        "USERINFO_ENCRYPTION_ENC_VALUES_SUPPORTED",
        "USERINFO_SIGNING_ALG_VALUES_SUPPORTED",
    }.ToFrozenSet();

    [Benchmark]
    public bool HashSetContains()
    {
        return OpenIdProviderMetadataNamesUpperCase.Contains("INTROSPECTION_ENDPOINT");
    }

    [Benchmark]
    public bool FrozenSetContains()
    {
        return OpenIdProviderMetadataNamesUpperCaseFrozenSet.Contains("INTROSPECTION_ENDPOINT");
    }
}

@joegoldman2 joegoldman2 requested a review from a team as a code owner June 17, 2024 19:59
@jennyf19 jennyf19 merged commit bf18516 into AzureAD:dev Jun 17, 2024
5 checks passed
@jennyf19
Copy link
Collaborator

thanks again @joegoldman2 for the contribution

@joegoldman2 joegoldman2 deleted the frozenset branch June 18, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants