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

Tweak code gen for Guid parsing #56210

Merged
merged 2 commits into from
Jul 25, 2021
Merged

Conversation

stephentoub
Copy link
Member

Following-up on @GrabYourPitchforks' suggestion in #55792 (comment)

Method Toolchain Mean Ratio Code Size
D \main\CoreRun.exe 38.43 ns 1.00 2,951 B
D \pr\CoreRun.exe 37.52 ns 0.98 2,900 B
N \main\CoreRun.exe 37.52 ns 1.00 2,302 B
N \pr\CoreRun.exe 37.08 ns 0.99 2,249 B
B \main\CoreRun.exe 39.30 ns 1.00 3,050 B
B \pr\CoreRun.exe 38.07 ns 0.97 2,999 B
P \main\CoreRun.exe 39.41 ns 1.00 3,055 B
P \pr\CoreRun.exe 38.85 ns 0.99 3,004 B
InvalidD \main\CoreRun.exe 42.55 ns 1.00 3,139 B
InvalidD \pr\CoreRun.exe 41.01 ns 0.96 3,088 B
WeirdD \main\CoreRun.exe 102.16 ns 1.00 3,418 B
WeirdD \pr\CoreRun.exe 100.44 ns 0.98 3,367 B

@dotnet-issue-labeler
Copy link

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.

@ghost
Copy link

ghost commented Jul 23, 2021

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Following-up on @GrabYourPitchforks' suggestion in #55792 (comment)

Method Toolchain Mean Ratio Code Size
D \main\CoreRun.exe 38.43 ns 1.00 2,951 B
D \pr\CoreRun.exe 37.52 ns 0.98 2,900 B
N \main\CoreRun.exe 37.52 ns 1.00 2,302 B
N \pr\CoreRun.exe 37.08 ns 0.99 2,249 B
B \main\CoreRun.exe 39.30 ns 1.00 3,050 B
B \pr\CoreRun.exe 38.07 ns 0.97 2,999 B
P \main\CoreRun.exe 39.41 ns 1.00 3,055 B
P \pr\CoreRun.exe 38.85 ns 0.99 3,004 B
InvalidD \main\CoreRun.exe 42.55 ns 1.00 3,139 B
InvalidD \pr\CoreRun.exe 41.01 ns 0.96 3,088 B
WeirdD \main\CoreRun.exe 102.16 ns 1.00 3,418 B
WeirdD \pr\CoreRun.exe 100.44 ns 0.98 3,367 B
Author: stephentoub
Assignees: -
Labels:

area-System.Runtime

Milestone: -

@stephentoub stephentoub added this to the 6.0.0 milestone Jul 23, 2021
@GrabYourPitchforks
Copy link
Member

Was hoping for a slightly better clock time measurement. But hey, I'll take the 50-byte codegen win. :)

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a 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;
}

@jeffhandley
Copy link
Member

@GrabYourPitchforks This PR is assigned to you for follow-up/decision before the RC1 snap.

@stephentoub
Copy link
Member Author

Here's another experiment

Thanks. Gives a small bump in throughput.

@stephentoub stephentoub merged commit ce3e00b into dotnet:main Jul 25, 2021
@stephentoub stephentoub deleted the guidparsetweak branch July 25, 2021 15:27
@ghost ghost locked as resolved and limited conversation to collaborators Aug 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants