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

Reduce allocations and transformations when creating a token. #2395

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

brentschmaltz
Copy link
Member

The purpose of this PR is to reduce the memory allocations when creating a JWS.
Strategy:

  1. Use ArrayPools whenever possible.
  2. Use a single MemoryStream at the highest level and make all writes into that stream.
  3. For .net 6+, add new API's to SignatureProviders to accept memory buffer to put signatures.
  4. Make use of Encoding.GetBytes that take a memory stream.

With these changes benchmark shows a slightly faster creation with less than half the memory.

For 1000 token creations using SecurityTokenDescriptor 2.48MB vs. 7.2MB.

Additional work for composing tokens where the memory buffer is passed to CreateToken.

Copy link
Contributor

@keegan-caruso keegan-caruso left a comment

Choose a reason for hiding this comment

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

Just a few small comments

@brentschmaltz brentschmaltz merged commit ab18767 into dev Dec 5, 2023
5 checks passed
@brentschmaltz brentschmaltz deleted the brentsch/SingleSpan branch December 5, 2023 18:42
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.

4 participants