Skip to content

Optimize AWS4Signer #3324

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

Merged
merged 13 commits into from
Jun 28, 2024
Merged

Conversation

danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented May 25, 2024

This PR heavily optimizes the HTTP header path on the AWS4Signer to reduce the number of allocations.

Description

See screenshots

Motivation and Context

Making sure the request path is less allocation heavy will drastically improve the throughput of the AWS SDK.

Testing

Screenshots (if appropriate)

CanonicalHeaderNames

CanonicalizeHeaderNames

https://github.com/danielmarbach/aws-sdk-net-benchmarks/blob/main/CanonicalHeaderNames.cs

CanonicalHeaders

CanonicalHeaders

https://github.com/danielmarbach/aws-sdk-net-benchmarks/blob/main/CanonicalHeaderNames.cs

CompressSpace

CompressSpace

https://github.com/danielmarbach/aws-sdk-net-benchmarks/blob/main/CompressSpace.cs

CanonicalHeaders with CompressSpace

CanonicalHeadersCompressSpace

https://github.com/danielmarbach/aws-sdk-net-benchmarks/blob/main/CanonicalHeaderNames.cs

Attention this was just a short run because things take ages otherwise

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@danielmarbach danielmarbach changed the base branch from main to v4-development May 25, 2024 14:00
@danielmarbach
Copy link
Contributor Author

@normj I would appreciate your input ;)

@dscpinheiro dscpinheiro added the v4 label May 30, 2024
@danielmarbach
Copy link
Contributor Author

@normj I have to update the description of the PR but I'm running out of my fun coding time allotted budget for now. I have added some benchmark results that should speak though themselves. Of course ideally it would be better if we could bring the ValueStringBuilder ref struct into the helper methods but since I did not get feedback on the usage of those protected static methods I went ahead and used an approach that doesn't require signature changes which I think is in your favor anyway for now.

@Dreamescaper I also addressed one of your feedbacks

@danielmarbach danielmarbach changed the title AWS4Signer using ValueStringBuilder Optimize AWS4Signer Jun 28, 2024
}

return builder.ToString();
return string.Join(";", sortedHeaders.Select(x => x.Key.ToLowerInvariant()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ran another benchmark on Fedora and decided to switch to ValueStringBuilder here too

image

@danielmarbach danielmarbach marked this pull request as ready for review June 28, 2024 16:16
Copy link
Contributor

@peterrsongg peterrsongg left a comment

Choose a reason for hiding this comment

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

I ran the core and custom unit tests, mainly was concerned about the existing Signer tests which pass. Change looks good to me.

Copy link
Member

@normj normj left a comment

Choose a reason for hiding this comment

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

Thanks @danielmarbach!

@normj normj merged commit 99ba6f1 into aws:v4-development Jun 28, 2024
2 checks passed
@danielmarbach danielmarbach deleted the valuestringbuilder branch June 28, 2024 20:52
@normj normj mentioned this pull request Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants