Dis.Uuid
1.1.0
dotnet add package Dis.Uuid --version 1.1.0
NuGet\Install-Package Dis.Uuid -Version 1.1.0
<PackageReference Include="Dis.Uuid" Version="1.1.0" />
<PackageVersion Include="Dis.Uuid" Version="1.1.0" />
<PackageReference Include="Dis.Uuid" />
paket add Dis.Uuid --version 1.1.0
#r "nuget: Dis.Uuid, 1.1.0"
#:package Dis.Uuid@1.1.0
#addin nuget:?package=Dis.Uuid&version=1.1.0
#tool nuget:?package=Dis.Uuid&version=1.1.0
Dis.Uuid
A high-performance .NET library for generating UUID version 7 (UUIDv7) identifiers with time-ordering capabilities.
๐ฏ What is UUID v7?
UUID version 7 is a time-ordered UUID variant that combines:
- 48-bit timestamp (millisecond precision)
- 12-bit random data for sub-millisecond ordering
- 62-bit random data for uniqueness
This design ensures:
- โ Chronological ordering - newer UUIDs are lexicographically greater
- โ Database performance - excellent for primary keys and indexes
- โ Global uniqueness - collision-resistant across distributed systems
- โ Thread safety - safe for concurrent use
๐ Installation
dotnet add package Dis.Uuid
Or via Package Manager Console:
Install-Package Dis.Uuid
๐ Usage
using Dis.Uuid;
// Generate a new UUID v7
Guid id = UuidV7.New();
Console.WriteLine(id); // e.g., 018f-4230-1234-7000-abcdef123456
// Use in your models
public class Order
{
public Guid Id { get; set; } = UuidV7.New();
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// ... other properties
}
๐ง Features
- High Performance: Uses
Span<byte>
andThreadLocal<RandomNumberGenerator>
for optimal performance - Thread Safe: Concurrent generation across multiple threads
- Memory Efficient: Zero heap allocations during UUID generation
- Standards Compliant: Follows RFC 4122 UUID v7 specification
- .NET 8+ Optimized: Takes advantage of latest .NET performance improvements
๐ Performance
UUID v7 generation is extremely fast and efficient:
// Benchmark example
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1_000_000; i++)
{
var uuid = UuidV7.New();
}
sw.Stop();
Console.WriteLine($"Generated 1M UUIDs in {sw.ElapsedMilliseconds}ms");
๐ Time Ordering
One of the key benefits of UUID v7 is natural time ordering:
var id1 = UuidV7.New();
await Task.Delay(1); // Small delay
var id2 = UuidV7.New();
// id2 will always be lexicographically greater than id1
Assert.True(string.Compare(id1.ToString(), id2.ToString()) < 0);
๐ฏ Use Cases
Perfect for:
- Database Primary Keys - Better performance than traditional UUIDs
- Distributed Systems - Global uniqueness with time ordering
- Event Sourcing - Natural chronological ordering of events
- Logging Systems - Time-ordered log entries
- Microservices - Consistent ID generation across services
๐ Thread Safety
The library is fully thread-safe and can be used concurrently:
// Safe to use across multiple threads
var tasks = Enumerable.Range(0, 10)
.Select(_ => Task.Run(() =>
{
var ids = new List<Guid>();
for (int i = 0; i < 1000; i++)
{
ids.Add(UuidV7.New());
}
return ids;
}));
var results = await Task.WhenAll(tasks);
// All generated UUIDs will be unique
๐งช Testing
The library includes comprehensive tests covering:
- Uniqueness validation
- Time ordering verification
- Thread safety testing
- Performance benchmarks
Run tests:
dotnet test
๐ Requirements
- .NET 8.0 or higher
- Compatible with all .NET 8+ workloads (Console, Web, Desktop, etc.)
๐ค Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if needed
- Submit a pull request
๐ License
This project is licensed under the BSD 3-Clause License - see the LICENSE.txt file for details.
๐ References
Made with โค๏ธ for the .NET community
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.0: Added compatibility with .NET Standard 2.0 (supports .NET Core 2.0+, .NET Framework 4.6.1+)