-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Tweak code gen for Guid parsing #56210
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsFollowing-up on @GrabYourPitchforks' suggestion in #55792 (comment)
|
Was hoping for a slightly better clock time measurement. But hey, I'll take the 50-byte codegen win. :) |
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.
Here's another experiment which may be worth running. Changing the definition of DecodeByte
to use nuint instead of char results in a 93-byte savings in the TryParse method (per sharplab). I'm not currently set up to measure how it might affect clock time.
private static byte DecodeByte(nuint ch1, nuint ch2, ref int invalidIfNegative)
{
// TODO https://github.com/dotnet/runtime/issues/13464:
// Replace the Unsafe.Add with HexConverter.FromChar once the bounds checks are eliminated.
ReadOnlySpan<byte> lookup = CharToHexLookup;
int h1 = -1;
if (ch1 < (nuint)lookup.Length)
{
h1 = (sbyte)Unsafe.Add(ref MemoryMarshal.GetReference(lookup), (nint)ch1);
}
h1 <<= 4;
int h2 = -1;
if (ch2 < (nuint)lookup.Length)
{
h2 = (sbyte)Unsafe.Add(ref MemoryMarshal.GetReference(lookup), (nint)ch2);
}
int result = h1 | h2;
invalidIfNegative |= result;
return (byte)result;
}
@GrabYourPitchforks This PR is assigned to you for follow-up/decision before the RC1 snap. |
Thanks. Gives a small bump in throughput. |
Following-up on @GrabYourPitchforks' suggestion in #55792 (comment)