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

Add Span overload(s) to TokenHandler #2157

Open
BrennanConroy opened this issue Jul 25, 2023 · 1 comment
Open

Add Span overload(s) to TokenHandler #2157

BrennanConroy opened this issue Jul 25, 2023 · 1 comment
Assignees
Labels
Enhancement The issue is a new feature Performance

Comments

@BrennanConroy
Copy link
Contributor

BrennanConroy commented Jul 25, 2023

While benchmarking an ASP.NET Core app we found that ~5% of allocations come from a substring call to remove "Bearer " from the access token provided in the "Authorization" header. We can avoid this substring call if TokenHandler.ValidateTokenAsync had a ReadOnlySpan<char> overload.

public virtual Task<TokenValidationResult> ValidateTokenAsync(string token, TokenValidationParameters validationParameters) => throw new NotImplementedException();

ASP.NET Core calls
https://github.com/dotnet/aspnetcore/blob/415cf1ec6d004648c27ab78359fd57d20c7c9797/src/Security/Authentication/JwtBearer/src/JwtBearerHandler.cs#L86
https://github.com/dotnet/aspnetcore/blob/415cf1ec6d004648c27ab78359fd57d20c7c9797/src/Security/Authentication/JwtBearer/src/JwtBearerHandler.cs#L107

Other methods like TokenHandler.ReadToken might also benefit, but I haven't analyzed them.

@jennyf19 jennyf19 added Enhancement The issue is a new feature .NET 8 Performance labels Jul 25, 2023
@brentschmaltz brentschmaltz added this to the December refresh milestone Oct 10, 2023
@keegan-caruso keegan-caruso removed this from the December refresh milestone Jan 19, 2024
@brentschmaltz
Copy link
Member

@BrennanConroy this PR is the first step, #2458

Once that is in, we plan on adding similar API's to JsonWebTokenHandler.ValidateToken(Span<>...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement The issue is a new feature Performance
Projects
None yet
Development

No branches or pull requests

5 participants