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

Do not create strings just for comparison #3411

Closed
1 of 2 tasks
paulomorgado opened this issue Aug 1, 2024 · 4 comments
Closed
1 of 2 tasks

Do not create strings just for comparison #3411

paulomorgado opened this issue Aug 1, 2024 · 4 comments
Labels
feature-request A feature should be added or improved. module/sdk-core p2 This is a standard priority issue

Comments

@paulomorgado
Copy link

paulomorgado commented Aug 1, 2024

Describe the feature

Amazon.Runtime.Internal.Marshaller.PreInvoke has this code:

#if NETSTANDARD
            var method = requestContext.Request.HttpMethod.ToUpperInvariant();
#else
            var method = requestContext.Request.HttpMethod.ToUpper(CultureInfo.InvariantCulture);
#endif
            if (method != "GET" && method != "DELETE" && method != "HEAD")

method is only used for comparison and can potentially be a newly allocated string.

Use Case

Creating objects that do not need to be created, not only uses memory and CPU to create them, but also causes GC work.

Proposed Solution

Use Equals(String, String, StringComparison) with StringComparison.OrdinalIgnoreCase, instead:

            var method = requestContext.Request.HttpMethod;
            if (!"GET".Equals(method, StringComparison.OrdinalIgnoreCase)
                && "DELETE".Equals(method, StringComparison.OrdinalIgnoreCase)
                && "HEAD".Equals(method, StringComparison.OrdinalIgnoreCase))

Ordinal ignore-case comparison can also be used in dictionaries, avoiding creating creating new strings just for index lookup.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS .NET SDK and/or Package version used

AWSSDK.KeyManagementService 3.7.300.52

Targeted .NET Platform

.NET 8

Operating System and version

Windows and Linux

@paulomorgado paulomorgado added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 1, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Aug 1, 2024

@paulomorgado Good morning. Thanks for opening the issue. Could you please point me to the exact location of code which you are referring to? I'm unable to find the code you are referring to here.

Thanks,
Ashish

@ashishdhingra ashishdhingra added p2 This is a standard priority issue needs-review response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. needs-review labels Aug 1, 2024
@dscpinheiro dscpinheiro removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 2, 2024
@bhoradc bhoradc added needs-review response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-review labels Aug 2, 2024
@ashovlin
Copy link
Member

ashovlin commented Aug 2, 2024

We refactored that code that was inspecting the HTTP verbs recently via #3338.

Though there are likely other occurrences of creating strings for comparisons that we can take a look at, if you have others that are in a hot spot?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 3, 2024
@paulomorgado
Copy link
Author

@paulomorgado Good morning. Thanks for opening the issue. Could you please point me to the exact location of code which you are referring to? I'm unable to find the code you are referring to here.

Thanks, Ashish

According to @ashovlin, this code has been replaced.

@bhoradc bhoradc closed this as completed Aug 9, 2024
Copy link

github-actions bot commented Aug 9, 2024

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. module/sdk-core p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

5 participants