-
Notifications
You must be signed in to change notification settings - Fork 413
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
Use Base64.DecodeFromUtf8InPlace #2504
Conversation
benchmark/Microsoft.IdentityModel.Benchmarks/Microsoft.IdentityModel.Benchmarks.csproj
Show resolved
Hide resolved
byte[] output = ArrayPool<byte>.Shared.Rent(outputSize); | ||
try | ||
{ | ||
Base64UrlEncoding.Decode(strSpan, startIndex, length, output); | ||
ReadOnlySpan<char> slice = strSpan.Slice(startIndex, length); | ||
Base64UrlEncoder.UnsafeDecode(slice, output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base64UrlEncoding.Decode(..)
was throwing ArgumentOutOfRangeException and ArgumentException exceptions. The new code path will not throw these exceptions. We might want to share this in the release notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good idea.
5e516ed
to
38d9b18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
7440712
to
487d7ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with suggestions. The code looks like it matches the previous one (except using the DecodeFromUtf8InPlace). Main suggestions are about refactoring a bit of the duplicate code. This class was a bit difficult to review since there are similarly named methods, duplicate code, and .NET6+ flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Use Base64.DecodeFromUtf8InPlace for base64 decode
Description
Base64.DecodeFromUtf8InPlace is SIMD aware.
CPU: ~ -12% on token read time
before:
after:
Note: this was run with a cpu with the following intrinsics: AVX-512F+CD+BW+DQ+VL+VBMI