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

Update ComputeHash to remove hash allocations for digest authentication #64005

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

vcsjones
Copy link
Member

@vcsjones vcsjones commented Jan 19, 2022

We can stop creating HashAlgorithm instances and instead use the one-shots.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 19, 2022
@ghost
Copy link

ghost commented Jan 19, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: vcsjones
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@@ -227,17 +227,25 @@ private static string GetRandomAlphaNumericString()

private static string ComputeHash(string data, string algorithm)
{
// Disable MD5 insecure warning.
Span<byte> hashBuffer = stackalloc byte[SHA256.HashSizeInBytes]; // SHA256 is the largest hash produced
byte[] dataBytes = Encoding.UTF8.GetBytes(data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this allocation be avoided?
E.g. by using a buffer from the array-pool or stack allocating for smaller data-length.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Honestly this whole file has a lot of opportunities to reduce string allocations. I held off on that since I was focusing just on how HashAlgorithm is being used throughout libraries.

@MihaZupan
Copy link
Member

@vcsjones were you planning on making other changes here or is this good to merge?
Test failure looks unrelated

@vcsjones
Copy link
Member Author

vcsjones commented Feb 1, 2022

@MihaZupan looks fine to merge to me, failure is #64389.

@vcsjones vcsjones merged commit b94b1df into dotnet:main Feb 1, 2022
@MihaZupan MihaZupan added this to the 7.0.0 milestone Feb 1, 2022
@vcsjones vcsjones deleted the hash-alloc-cleanup branch February 1, 2022 17:52
@ghost ghost locked as resolved and limited conversation to collaborators Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants