You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[API Proposal]: Uuid v5 and v7 implementations into System.Guid #88290
With the increase of distributed storage, and extensive use of uuid in databases, uuid v4 insert times grow linearly making inefficient its use for primary keys.
New versions are proven to have less impact on indexes than v4.
A first benchmark with Uuid7 in my 8 core machine with docker/postgres 15 shows:
inserting 1 million uuid v4 with EFCore takes 8.5 seconds with an empty table, and 16 seconds with 12750000 rows (table is only id)
inserting 1 million uuid v7 with EFCore takes 8.5 seconds with an empty table, and 9 seconds with 12750000 rows (table is only id)
A quick benchmark is 98% fragmentation for UUIDv7 vs 44% for sequential GUID for 100k inserted records.
Hi Robbie, yes, but that's SQL server specific that's why I didn't mention, yet still in proposal v7 hopefully can land into an official format.
I guess until is approved this will remain inactive or closed... Let's see
I opened now because seems like Microsoft takes time to implement new things refer to SHA3
The container proposed in this API Proposal could have been an excellent data type for storing Uuid v5 and v7, as well as any other versions, but it was closed. The alternative proposed option, in my opinion, does not solve the problems described here.
UUID v5 and v7 have to do with how new values are constructed. It has little to do with the storage mechanism of the underlying bits.
Once a correct sequence of bits has been generated, it can then be serialized as required by the consumer. For some scenarios, this will be BigEndian format and for others LittleEndian format and which exactly is "correct" depends on how the consumer will interpret a raw sequence of 16-bytes.
API Proposal
It should probably be called NewGuid, rather than NewUuid, to match the existing naming and general framework design guidelines conventions. As per the UUID specification, GUID is simply an alternative name:
This specification defines a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier).
And as per the existing NewGuid docs:
The method creates a Version 4 Universally Unique Identifier (UUID) as described in RFC 4122, Sec. 4.4
There will probably be some discussion as to whether they should be called NewGuid5, NewGuidV5, or NewGuidVersion5. There may also be some discussion on whether this should simply be NewGuid(int version) or something like NewGuid(GuidVersion version) for some enum GuidVersion.
Exposing version 5 is likely to be non-controversial as its already been formally reserved and defined by the RFC 4122 specification. Exposing methods for versions 1, 2, and 3 would probably be uncontroversial for similar reasons.
Exposing version 7 may get rejected on the basis that its not been formally ratified yet. The same would be true for versions 6 and 8. I expect that it would become uncontroversial once ratification is complete. -- This is namely because we would no longer have the flexibility to be compliant if anything changed between shipping such an API and ratification finalizing.
There may likewise need to be discussion on if the methods need any parameterization. NewGuid() itself is version 4 which is "random data". Other versions have different inputs or parameterization used to influence the generation. This is roughly:
version 1 is time based using 60-bits to represent the number of 100ns intervals in UTC since 15 OCT 1582
version 2 is for DCE Security
version 3 is from an MD5 hash over a given namespace value
version 4 is 128-bits of random data, replacing 6 bits with fixed values
version 5 is a SHA-1 hash over a given namespace value
version 6 is just version 1 with the bits stored in different positions
version 7 is similar to v1/6 but uses 48-bits representing the number of milliseconds in UTC since 1 JAN 1970 (Unix Epoch) + optional and otherwise random data for the remaining unused bits
version 8 is supposed to be set aside for vendor specific use-case and experimentation
Also noting, with regards to the parameterization, the UUID spec covers:
While Appendix A details a few interesting namespaces; implementations SHOULD provide the ability to input a custom namespace. For example, any other UUID MAY be generated and used as the desired namespace input for a given application context to ensure all names created are unique within the newly created namespace.
Reacted by Joe4evr, Matteo Contrini, David Ruhmann, yieldOnly, nkosi23, agoodwin and 、Idea
version 7 is similar to v1/6 but uses 48-bits representing the number of milliseconds in UTC since 1 JAN 1970 (Unix Epoch) + optional and otherwise random data for the remaining unused bits
Does this affect what it means to serialize as big vs little endian? The six bytes comprising that value won't be reversed on their own and will thus change where they are in the resulting byte order.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| unix_ts_ms |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| unix_ts_ms | ver | rand_a |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var| rand_b |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| rand_b |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 11: UUIDv7 Field and Bit Layout
unix_ts_ms:
48 bit big-endian unsigned number of Unix epoch timestamp in
milliseconds as per Section 6.1.
ver:
4 bit UUIDv7 version set as per Section 4.2
rand_a:
12 bits pseudo-random data to provide uniqueness as per
Section 6.8 and/or optional constructs to guarantee additional
monotonicity as per Section 6.2.
var:
The 2 bit variant defined by Section 4.1.
rand_b:
The final 62 bits of pseudo-random data to provide uniqueness as
per Section 6.8 and/or an optional counter to guarantee additional
monotonicity as per Section 6.2.
And the general layout description in the spec has been simplified to:
5. UUID Layouts
To minimize confusion about bit assignments within octets and among
differing versions, the UUID record definition is provided as a
grouping of fields within bit layout consisting four octets to a row.
The fields are presented with the most significant one first.
Thus, the latest draft spec defaults to Variant 1 (0b10x) and what is effectively "BigEndian" layout.
The Variant 2 (0b110) layout that System.Guid defaults to is simply uint, ushort, ushort, byte[8] and thus its only the first 8-bytes that are effected by endianness and which differ, the last 8 bytes are always identical to Variant 1.
So we'd serialize it correctly if the user specifies ToByteArray(bigEndian: true) and deserialize it correctly given new Guid(array, isBigEndian: true). That is, the two layouts are
UUID v5 and v7 have to do with how new values are constructed. It has little to do with the storage mechanism of the underlying bits.
I will quote the proposal of the new uuid versions to answer.
You can read the proposal here
So is not me who says that, is the reason to have a pseudo sequential generate random IDs.
One area UUIDs have gained popularity is as database keys. This stems from the increasingly distributed nature of modern applications. In such cases, "auto increment" schemes often used by databases do not work well, as the effort required to coordinate unique numeric identifiers across a network can easily become a burden. The fact that UUIDs can be used to create unique, reasonably short values in distributed systems without requiring synchronization makes them a good alternative, but UUID versions 1-5 lack certain other desirable characteristics:
The only thing missing is Guid type support for formatting LE UUIDs, which we will hopefully get soon.
The container proposed in this API Proposal could have been an excellent data type for storing Uuid v5 and v7, as well as any other versions, but it was closed. The alternative proposed option, in my opinion, does not solve the problems described here.
Am I missing something? The proposal (with bigEndian boolean) completely solves the issue, it allow us to add APIs mentioned in the original post like Guid.NewUuid7().
So we'd serialize it correctly if the user specifies ToByteArray(bigEndian: true) and deserialize it correctly given new Guid(array, isBigEndian: true)
I'm not concerned about whether we'd roundtrip it well; we could output any order we wanted and as long as we used the same order for deserialization it would roundtrip :)
My question is really:
we'd end up taking the first 32-bits of the 48-bit unix_ts_ms and reversing the bytes in those, and then the next 16-bits of the 48-bit unix_ts_ms and reversing the bytes in those, such that we didn't actually reverse all the bytes in the 48-bit value.
the reason we're exposing the big endian APIs is for interop with other systems
so, will other systems understand this schema of reversing portions of unix_ts_ms in this way?
Or asked another way, do the new APIs we've approved make sense to use with Guids created from the APIs proposed in this issue?
The internal field layout used by a given runtime (for it's GUID/UUID type) has very little to do with the actual data being tracked. It only matters for scenarios where you are unsafely accessing the raw bytes of the struct, such as via pointers, other forms of reinterpret like casting, or in the case you are implementing official serialization/deserialization APIs for the type.
.NET's internal field layout is, due to historical reasons, compatible with the Microsoft GUID type defined by the Win32 header files. This is formally defined as the following, which in .NET is uint, ushort, ushort, fixed byte[8]:
This definition has not fundamentally changed since its original introduction and its not going to change in the future either, because doing so would be massively breaking to the entire Windows ecosystem. Since these are just regular fields, the byte order observed via unsafe code matches the endianness of the host system. Since Windows does not currently support any big endian systems, the layout in practice appears to users as always being "little endian" and discussions often simplify it down to this, even if its not "technically correct".
This also means that the layout of these bytes is "functionally fixed". Given a GUID/UUID of 6B29FC40-CA47-1067-B31D-00DD010662DA, Data1 is always equal to 0x6B29FC40, Data2 is always equal to 0xCA47, Data3 is always equal to 0x1067, and Data4 is always equal to { 0xB3, 0x1D, 0x00, 0xDD, 0x01, 0x06, 0x62, 0xDA }, regardless of the endianness of the underlying system. This then translates over to every single other representable value and so the layout is always well-defined for such a struct.
The NewGuid() API that exists today generates a "spec compliant" 128-bit GUID/UUID following the variant 1, version 4 mechanism described by RFC 4122. Which is to say it generates 122-bits of random data setting the variant field to 0b10x and the version field to 0b0100. The general format of this is xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx where M represents the version, N represents the variant, and x represents "random data". Since the encoding of variant 1 in the N location is itself described as 0b10xx, we then have 4 baseline masks:
This proposal is simply asking for additional functions which would generate variant 1, version 5 and variant 1, version 7 mechanisms described by the latest RFC 4122 draft specification. This would be generally the same as the above but with the M location being 5 -or- 7, rather than 4. The x locations would likewise be generated as per the specification rather than being "random data".
it does not actually mean MSFT flavor = Little Endian = Variant 2
The general discussion was being somewhat simplified as it basically boils down to, in practice, that Windows uses "little endian" and many other (but not all) systems use "big endian". In both cases, this is regardless of the variant/version.
Ultimately, users who need to serialize a Guid as a sequence of 16-bytes should use the relevant API and pass in the appropriate true or false value to isBigEndian depending on which byte layout they need. This will typically be true for developers interacting with various Unix APIs or systems, some types of networking, and some databases. This will typically be false for developers interacting with COM and various Windows APIs or systems. The "correct" value will be scenario dependent.
There is no need to discuss hypothetical alternative layouts which are extremely unlikely to be encountered in practice and the APIs being exposed are sufficient for what is effectively the two de-facto layouts users will actually encounter.
This proposal is simply asking for additional functions which would generate variant 1, version 5 and variant 1, version 7
I'm interested specifically in Variant 1 Version 7, specifically, whether the fundamental property of v7 - time-based ordering will be preserved with current layout, and will it be compatible with changes from #86798
I.e., Consider {t1, t2, ... tN} is a sequence of timestamps, and {g1, g2, ... gN} is a sequence of v7 Guids produced at these timestamps. Now, if t1 < t2 < ... tN, will it also be true that g1 < g2 < ... < gN. In code, in string serialized form, in little-endian binary serialized form (e.g. in SqlServer), and in big-endian serialized form (e.g. in PostgreSql)
Just as the 32-bit unsigned integer 0x0000_0001 is always 1 regardless of big-endian ({ 0x00, 0x00, 0x00, 0x01 }) or little-endian ({ 0x01, 0x00, 0x00, 0x00 }) and therefore always compares less than 0x0000_0002.
The same is true that 6B29FC40-CA47-1067-B31D-00DD010662DA is always this exact GUID, regardless of how its stored. It is compared as if it were a 128-bit unsigned integer 0x6B29FC40_CA471067_B31D00DD_010662DA and therefore will compare less than 0x6B29FC41_CA471067_B31D00DD_010662DA (6B29FC41-CA47-1067-B31D-00DD010662DA) and so on.
In the proposal: public static Guid NewUuid5()
But v5 is namespace based Guid's.
Signature for Guid v5 would be something like: public static Guid NewUuid5(Guid namespace, string name)
Reacted by Evgeniy Alexandrov, Kalle Olavi Niemitalo and yieldOnly
Yes, you're right, it is namespace based - so the signature would be different.
However, it's also the reason it probably won't be implemented in BCL. Namespace based UUIDs (v3 and v5) use MD5 and SHA-1 hash functions to construct an actual binary value. These hash functions are considered vulnerable, so MSFT has an outright ban on any new usage of MD5/SHA-1, even in non-cryptographic context.
It is compared as if it were a 128-bit unsigned integer 0x6B29FC40_CA471067_B31D00DD_010662DA and therefore will compare less than 0x6B29FC41_CA471067_B31D00DD_010662DA (6B29FC41-CA47-1067-B31D-00DD010662DA) and so on.
I expect this won't happen in .NET 9, it's a bit late in the cycle with about 1-2 months before the time we normally snap for RC1.
There's a lot of other work across the stack that is already the focus and a priority, but this can potentially be included for .NET 10. In order for that to happen (or to even attempt getting it in for .NET 9 if there's community members willing to do the work), the proposed surface needs to be updated to account for some of the feedback given here.
Namely we should ensure that signatures exist that make sense given the existing APIs on System.Guid and which take in any necessary parameters. The proposal should likely include a link to the spec and a small explanation of the layout for the given version and how the parameters are used in constructing the value.
For example, UUIDv5 is generated using bits from the SHA-1 of a string namespaceId + string name, but there may be considerations based on it being SHA-1 based as well, since SHA-1 is no longer recommended for use. While for UUIDv7 there likely needs to be consideration about how the Unix timestamp is seeded (is it automatic, can the user provide one explicitly, etc). There should likely also be a consideration on whether support for other stable UUID versions should be provided simultaneously (noting that we have UUIDv4 already via NewGuid())
While its characteristics are desirable, the fact that it is a custom type (struct Ulid) has caused significant frustration because the .NET ecosystem and databases require GUIDs.
Therefore, I strongly believe it is very desirable for UUIDv7 to be provided as a standard and for its type to be GUID.
I hope for its early adoption (in .NET 9!).
Activity
rgroenewoudt commentedon Jul 1, 2023
Please note that SQL Server needs a different ordering for unique identifier. Their sequential GUIDs work better then UUIDv7. For example: https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Id/GuidCombGenerator.cs
A quick benchmark is 98% fragmentation for UUIDv7 vs 44% for sequential GUID for 100k inserted records.
dariogriffo commentedon Jul 1, 2023
Hi Robbie, yes, but that's SQL server specific that's why I didn't mention, yet still in proposal v7 hopefully can land into an official format.
I guess until is approved this will remain inactive or closed... Let's see
I opened now because seems like Microsoft takes time to implement new things refer to SHA3
vanbukin commentedon Jul 1, 2023
The container proposed in this API Proposal could have been an excellent data type for storing Uuid v5 and v7, as well as any other versions, but it was closed. The alternative proposed option, in my opinion, does not solve the problems described here.
tannergooding commentedon Jul 1, 2023
UUID v5 and v7 have to do with how new values are constructed. It has little to do with the storage mechanism of the underlying bits.
Once a correct sequence of bits has been generated, it can then be serialized as required by the consumer. For some scenarios, this will be
BigEndianformat and for othersLittleEndianformat and which exactly is "correct" depends on how the consumer will interpret a raw sequence of 16-bytes.It should probably be called
NewGuid, rather thanNewUuid, to match the existing naming and general framework design guidelines conventions. As per theUUIDspecification,GUIDis simply an alternative name:And as per the existing
NewGuiddocs:There will probably be some discussion as to whether they should be called
NewGuid5,NewGuidV5, orNewGuidVersion5. There may also be some discussion on whether this should simply beNewGuid(int version)or something likeNewGuid(GuidVersion version)for someenum GuidVersion.Exposing
version 5is likely to be non-controversial as its already been formally reserved and defined by theRFC 4122specification. Exposing methods forversions 1, 2, and 3would probably be uncontroversial for similar reasons.Exposing
version 7may get rejected on the basis that its not been formally ratified yet. The same would be true forversions 6 and 8. I expect that it would become uncontroversial once ratification is complete. -- This is namely because we would no longer have the flexibility to be compliant if anything changed between shipping such an API and ratification finalizing.There may likewise need to be discussion on if the methods need any parameterization.
NewGuid()itself isversion 4which is "random data". Other versions have different inputs or parameterization used to influence the generation. This is roughly:version 1is time based using 60-bits to represent the number of100nsintervals in UTC since15 OCT 1582version 2is for DCE Securityversion 3is from an MD5 hash over a given namespace valueversion 4is 128-bits of random data, replacing 6 bits with fixed valuesversion 5is a SHA-1 hash over a given namespace valueversion 6is justversion 1with the bits stored in different positionsversion 7is similar tov1/6but uses 48-bits representing the number ofmillisecondsin UTC since1 JAN 1970(Unix Epoch) + optional and otherwise random data for the remaining unused bitsversion 8is supposed to be set aside for vendor specific use-case and experimentationAlso noting, with regards to the parameterization, the UUID spec covers:
stephentoub commentedon Jul 1, 2023
Does this affect what it means to serialize as big vs little endian? The six bytes comprising that value won't be reversed on their own and will thus change where they are in the resulting byte order.
tannergooding commentedon Jul 1, 2023
The actual definition of
Version 7is:And the general layout description in the spec has been simplified to:
Thus, the latest draft spec defaults to
Variant 1(0b10x) and what is effectively "BigEndian" layout.The
Variant 2(0b110) layout thatSystem.Guiddefaults to is simplyuint, ushort, ushort, byte[8]and thus its only the first 8-bytes that are effected by endianness and which differ, the last 8 bytes are always identical toVariant 1.So we'd serialize it correctly if the user specifies
ToByteArray(bigEndian: true)and deserialize it correctly givennew Guid(array, isBigEndian: true). That is, the two layouts aredariogriffo commentedon Jul 2, 2023
I will quote the proposal of the new uuid versions to answer.
You can read the proposal here
So is not me who says that, is the reason to have a pseudo sequential generate random IDs.
GunboatDiplomat commentedon Jul 2, 2023
If you are using UUIDs for purpose of DB indexing, I would recommend https://github.com/mareek/UUIDNext. It uses v7 for most DBs and a custom v8 low endian format for MSSQL.
The only thing missing is Guid type support for formatting LE UUIDs, which we will hopefully get soon.
Am I missing something? The proposal (with bigEndian boolean) completely solves the issue, it allow us to add APIs mentioned in the original post like
Guid.NewUuid7().stephentoub commentedon Jul 3, 2023
I'm not concerned about whether we'd roundtrip it well; we could output any order we wanted and as long as we used the same order for deserialization it would roundtrip :)
My question is really:
Or asked another way, do the new APIs we've approved make sense to use with Guids created from the APIs proposed in this issue?
3 remaining items
tannergooding commentedon Jul 5, 2023
The internal field layout used by a given runtime (for it's
GUID/UUIDtype) has very little to do with the actual data being tracked. It only matters for scenarios where you are unsafely accessing the raw bytes of the struct, such as via pointers, other forms of reinterpret like casting, or in the case you are implementing official serialization/deserialization APIs for the type..NET's internal field layout is, due to historical reasons, compatible with the Microsoft
GUIDtype defined by the Win32 header files. This is formally defined as the following, which in .NET isuint, ushort, ushort, fixed byte[8]:This definition has not fundamentally changed since its original introduction and its not going to change in the future either, because doing so would be massively breaking to the entire Windows ecosystem. Since these are just regular fields, the byte order observed via unsafe code matches the endianness of the host system. Since Windows does not currently support any big endian systems, the layout in practice appears to users as always being "little endian" and discussions often simplify it down to this, even if its not "technically correct".
This also means that the layout of these bytes is "functionally fixed". Given a
GUID/UUIDof6B29FC40-CA47-1067-B31D-00DD010662DA,Data1is always equal to0x6B29FC40,Data2is always equal to0xCA47,Data3is always equal to0x1067, andData4is always equal to{ 0xB3, 0x1D, 0x00, 0xDD, 0x01, 0x06, 0x62, 0xDA }, regardless of the endianness of the underlying system. This then translates over to every single other representable value and so the layout is always well-defined for such a struct.The
NewGuid()API that exists today generates a "spec compliant" 128-bitGUID/UUIDfollowing thevariant 1, version 4mechanism described byRFC 4122. Which is to say it generates 122-bits of random data setting thevariantfield to0b10xand theversionfield to0b0100. The general format of this isxxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxxwhereMrepresents theversion,Nrepresents thevariant, andxrepresents "random data". Since the encoding ofvariant 1in theNlocation is itself described as0b10xx, we then have 4 baseline masks:This proposal is simply asking for additional functions which would generate
variant 1, version 5andvariant 1, version 7mechanisms described by the latestRFC 4122draft specification. This would be generally the same as the above but with theMlocation being5-or-7, rather than4. Thexlocations would likewise be generated as per the specification rather than being "random data".The general discussion was being somewhat simplified as it basically boils down to, in practice, that Windows uses "little endian" and many other (but not all) systems use "big endian". In both cases, this is regardless of the variant/version.
Ultimately, users who need to serialize a
Guidas a sequence of 16-bytes should use the relevant API and pass in the appropriatetrueorfalsevalue toisBigEndiandepending on which byte layout they need. This will typically betruefor developers interacting with various Unix APIs or systems, some types of networking, and some databases. This will typically befalsefor developers interacting with COM and various Windows APIs or systems. The "correct" value will be scenario dependent.There is no need to discuss hypothetical alternative layouts which are extremely unlikely to be encountered in practice and the APIs being exposed are sufficient for what is effectively the two de-facto layouts users will actually encounter.
aloraman commentedon Jul 5, 2023
I'm interested specifically in
Variant 1 Version 7, specifically, whether the fundamental property ofv7- time-based ordering will be preserved with current layout, and will it be compatible with changes from #86798I.e., Consider {t1, t2, ... tN} is a sequence of timestamps, and {g1, g2, ... gN} is a sequence of
v7Guids produced at these timestamps. Now, if t1 < t2 < ... tN, will it also be true that g1 < g2 < ... < gN. In code, in string serialized form, in little-endian binary serialized form (e.g. in SqlServer), and in big-endian serialized form (e.g. in PostgreSql)tannergooding commentedon Jul 5, 2023
Endianness makes no difference as to the value.
Just as the 32-bit unsigned integer
0x0000_0001is always1regardless of big-endian ({ 0x00, 0x00, 0x00, 0x01 }) or little-endian ({ 0x01, 0x00, 0x00, 0x00 }) and therefore always compares less than0x0000_0002.The same is true that
6B29FC40-CA47-1067-B31D-00DD010662DAis always this exact GUID, regardless of how its stored. It is compared as if it were a 128-bit unsigned integer0x6B29FC40_CA471067_B31D00DD_010662DAand therefore will compare less than0x6B29FC41_CA471067_B31D00DD_010662DA(6B29FC41-CA47-1067-B31D-00DD010662DA) and so on.osexpert commentedon Jul 8, 2023
In the proposal: public static Guid NewUuid5()
But v5 is namespace based Guid's.
Signature for Guid v5 would be something like: public static Guid NewUuid5(Guid namespace, string name)
aloraman commentedon Jul 10, 2023
Yes, you're right, it is namespace based - so the signature would be different.
However, it's also the reason it probably won't be implemented in BCL. Namespace based UUIDs (v3 and v5) use MD5 and SHA-1 hash functions to construct an actual binary value. These hash functions are considered vulnerable, so MSFT has an outright ban on any new usage of MD5/SHA-1, even in non-cryptographic context.
osexpert commentedon Aug 6, 2023
According to this there is no standard way to CompareTo\order a Guid:
https://devblogs.microsoft.com/oldnewthing/20190426-00/?p=102450
tannergooding commentedon Aug 7, 2023
That’s referring to the across all GUID types.
The .NET System.Guid type has long had a standardized sorting behavior and matches how I detailed it above.
matteocontrini commentedon May 22, 2024
The new UUIDs specification was published a few days ago with RFC 9562: https://datatracker.ietf.org/doc/rfc9562/
Any chance this could now be prioritized?
memark commentedon May 31, 2024
Looking forward to this as well!
In the meantime, my praise goes to @tannergooding for his thorough and insightful posts in this thread.
tannergooding commentedon May 31, 2024
I expect this won't happen in .NET 9, it's a bit late in the cycle with about 1-2 months before the time we normally snap for RC1.
There's a lot of other work across the stack that is already the focus and a priority, but this can potentially be included for .NET 10. In order for that to happen (or to even attempt getting it in for .NET 9 if there's community members willing to do the work), the proposed surface needs to be updated to account for some of the feedback given here.
Namely we should ensure that signatures exist that make sense given the existing APIs on
System.Guidand which take in any necessary parameters. The proposal should likely include a link to the spec and a small explanation of the layout for the given version and how the parameters are used in constructing the value.For example,
UUIDv5is generated using bits from theSHA-1of astring namespaceId + string name, but there may be considerations based on it being SHA-1 based as well, since SHA-1 is no longer recommended for use. While forUUIDv7there likely needs to be consideration about how the Unix timestamp is seeded (is it automatic, can the user provide one explicitly, etc). There should likely also be a consideration on whether support for other stableUUIDversions should be provided simultaneously (noting that we haveUUIDv4already viaNewGuid())neuecc commentedon Jun 18, 2024
I have created a library for Ulid (890 stars) that has similar characteristics to UUIDv7.
https://github.com/Cysharp/Ulid
While its characteristics are desirable, the fact that it is a custom type (struct Ulid) has caused significant frustration because the .NET ecosystem and databases require GUIDs.
Therefore, I strongly believe it is very desirable for UUIDv7 to be provided as a standard and for its type to be GUID.
I hope for its early adoption (in .NET 9!).
tannergooding commentedon Jun 24, 2024
I opened #103658 which covers this for UUIDv7 and opens the path to also do it for UUIDv5 in the future if that's desired