-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
I got nerd-sniped on Mastodon a while back into build a highly performant UUIDv7 implementation for .NET.
I haven't published it as a library yet or anything like that.
I just saw that .NET 9 Preview 7 adds Guid.CreateVersion7() which does the same thing, but when I benchmarked it the runtime version came out as almost 3x as slow as my version.
The problem is my version depends on being smart with RandomNumberGenerator.Fill, and based on this comment it seems that random number generation is not available in this part of the runtime and what is available is slower
However I think there may be an oversight here.
RandomNumberGenerator.Fill is significantly faster on macOS, but about 20% slower on Windows. I suspect this is due to the split between CoCreateGuid() on Windows vs Interop.GetCryptographicallySecureRandomBytes() on Unix.
I'll post additional benchmarks below.
Would you be open to me doing platform-specific implementations to speed up Guid.CreateVersion7() (and if I can get benchmarks to back it up, maybe Guid.NewGuid() too?) on non-Windows platforms?