-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Spanified Webencoders.Base64UrlEncode #11047
Conversation
To resolve the code check failure, run Also, there look to be some compile errors. |
Ah, didn't realize the usage over there. Thx.
E.g.
I believed it's .NET Core 3.0 only...proved wrong 😢 Will fix this in the next commit (Edit: in the next one...) |
The code-check fails. Will generate the ref-assembly again tomorrow. There's same strange in my local setup with not found target-frameworks, etc (I followed the steps documented in this repo, so I assume it's me doing something wrong). |
Gave it another try. Failed it before because I moved the method down in 64db801? By executing the command from #11047 (comment) I get (linux-box):
Is this known / expected? |
@aspnet/build Does GenerateReferenceSource not work on Linux if net461 is a tfm? |
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.
Super happy 😄
I don't think GenerateReferenceSource works on Linux at all due to MSBuild not handling line endings and slashes properly. |
Thanks @gfoidl ! |
@natemcmaster on linux the ref-assembly was generated correctly, but the command showed the above failure. The ref-assembly is for netcoreapp3.0 only, maybe that's why it worked. |
Added
string Base64UrlEncode(ReadOnlySpan<byte> input)
to WebEncoders, andredirected the other
string Base64UrlEncode(...)
-methods to use the spanified version.Used this new method in SignalR's
HttpConnectionManager.MakeNewConnectionId
.So in total it safes two allocations. One in
MakeNewConnectionId
, as the buffer is stackalloced, the other one in the base64 encoding, as the buffer is stackalloced or rented from theArrayPool
.Addresses dotnet/extensions#456
Note:
This fix just safes the allocations. In this PR no attempt was made to do base64Url
encoding directly -- i.e. as O(n) operation instead a O(2n) as used here, where in the
base64 encoded results
+
and/
are substituted (see dotnet/extensions#338 for a (declined) PR that does this directly).Further no attempt was made to vectorize the encoding (similar to dotnet/corefx#34529, or as used in https://github.com/gfoidl/Base64).
Perf-improvments will come for free once dotnet/coreclr#21833 is merged.
/CC: @BrennanConroy