-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Vectorize Guid.ToString #81650
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
Vectorize Guid.ToString #81650
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. |
Co-authored-by: Miha Zupan <[email protected]>
@stephentoub @MihaZupan anything else? |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsI tried to keep the implementation compact - around +66 lines to handle D, N, P and B formats (except X basically, which is rarely-used). For both x64 and Arm64. public static IEnumerable<Guid> TestData()
{
yield return new Guid("{483BC244-A481-4D29-986F-8C7D647AA20D}");
}
[Benchmark]
[ArgumentsSource(nameof(TestData))]
public string ToStringD(Guid guid) => guid.ToString(); // Default - "D"
[Benchmark]
[ArgumentsSource(nameof(TestData))]
public string ToStringN(Guid guid) => guid.ToString("N");
[Benchmark]
[ArgumentsSource(nameof(TestData))]
public string ToStringB(Guid guid) => guid.ToString("B");
[Benchmark]
[ArgumentsSource(nameof(TestData))]
public string ToStringP(Guid guid) => guid.ToString("P");
The main motivation was to slightly speed up JSON serialization for Guid fields, e.g.: record Entity(Guid Id, string Name);
string json = JsonSerializer.Serialize(entity, EntityJsonContext.Default.Entity); Around 5% improvement here.
|
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.
will move hand-made Vector128 crossplat helpers to Vector128 itself (clean up) in my next PR
You can skip the Shuffle (#80963 already does it) -- I'll rebase once your PR is merged.
Co-authored-by: Stephen Toub <[email protected]>
I tried to keep the implementation compact - around +66 lines to handle D, N, P and B formats (except X basically, which is rarely-used). For both x64 and Arm64.
The main motivation was to slightly speed up JSON serialization for Guid fields, e.g.:
Around 5% improvement here.