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
Commit 0a693bc
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,14 @@ and this project aims to follow [Semantic Versioning](https://semver.org/spec/v2
7
7
8
8
## [Unreleased]
9
9
10
+
### Added
11
+
- Add opt-in `UuidV7FactoryStatistics` counters for generated UUIDs, clock rollback, counter overflow, spin-wait, logical drift, CAS retries, and random-buffer refills.
12
+
10
13
### Changed
11
14
-`HlcGuidFactory` constructor now enforces a 14-bit node ID constraint and throws `ArgumentOutOfRangeException` for values above `HlcGuidFactory.MaxNodeId` (16383). Previously, higher values were silently truncated in generated UUIDv7 values.
12
15
13
16
### Documentation
17
+
- Document UUIDv7 factory statistics and counter semantics.
14
18
- Clarify `UuidV7Factory` collision and clock-skew guarantees, including the distinction between per-instance deterministic monotonicity and probabilistic cross-factory uniqueness.
15
19
- Document the custom RNG contract for `UuidV7Factory`, including deterministic replay behavior and production CSPRNG guidance.
Copy file name to clipboardExpand all lines: docs/changelog.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,14 @@ This page mirrors the repository root `CHANGELOG.md`.
10
10
11
11
## [Unreleased]
12
12
13
+
### Added
14
+
- Add opt-in `UuidV7FactoryStatistics` counters for generated UUIDs, clock rollback, counter overflow, spin-wait, logical drift, CAS retries, and random-buffer refills.
15
+
13
16
### Changed
14
17
-`HlcGuidFactory` constructor now enforces a 14-bit node ID constraint and throws `ArgumentOutOfRangeException` for values above `HlcGuidFactory.MaxNodeId` (16383). Previously, higher values were silently truncated in generated UUIDv7 values.
15
18
16
19
### Documentation
20
+
- Document UUIDv7 factory statistics and counter semantics.
17
21
- Clarify `UuidV7Factory` collision and clock-skew guarantees, including the distinction between per-instance deterministic monotonicity and probabilistic cross-factory uniqueness.
18
22
- Document the custom RNG contract for `UuidV7Factory`, including deterministic replay behavior and production CSPRNG guidance.
Statistics are disabled unless you pass an instance to the factory. When enabled, counters use atomic operations so they can be read safely while UUIDs are being generated concurrently.
57
+
58
+
Useful counters include:
59
+
60
+
-`GeneratedCount`
61
+
-`ClockRollbackCount`
62
+
-`CounterOverflowCount`
63
+
-`SpinWaitCount`
64
+
-`LogicalTimestampAdvanceCount`
65
+
-`MaxLogicalDriftMs`
66
+
-`CasRetryCount`
67
+
-`RandomBufferRefillCount`
68
+
69
+
Use `Snapshot()` when you need a point-in-time value object, and `Reset()` to isolate test phases:
70
+
71
+
```csharp
72
+
stats.Reset();
73
+
```
74
+
36
75
## Timeout statistics
37
76
38
77
Timeout factory helpers (`Timeouts`) can record aggregate timeout activity via `TimeoutStatistics`.
@@ -58,4 +97,3 @@ If you prefer isolation per test (or per component), pass your own `TimeoutStati
Copy file name to clipboardExpand all lines: docs/guide/uuidv7.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,46 @@ For production services, prefer a single `UuidV7Factory` singleton per process o
68
68
69
69
For high-assurance shared namespaces, use a storage uniqueness constraint as the final guardrail and retry on conflict. If you need node-aware ordering semantics, consider `HlcGuidFactory`; it embeds a node ID and HLC timestamp, but it should be chosen for causal/node-aware ordering rather than treated as a blanket substitute for storage-level uniqueness.
70
70
71
+
## Statistics
72
+
73
+
`UuidV7Factory` statistics are opt-in. Leave them disabled for the lowest-overhead path, or pass a `UuidV7FactoryStatistics` instance when you want to observe clock rollback, counter overflow, spin-wait pressure, and lock-free contention:
|`GeneratedCount`| Number of UUIDs successfully generated. Batch generation increments by the span length. |
101
+
|`ClockRollbackCount`| Successful allocation decisions made while physical time was behind the factory's logical frontier. |
102
+
|`CounterOverflowCount`| Times the 12-bit per-millisecond counter overflow path was reached. |
103
+
|`SpinWaitCount`| Times overflow handling had to wait for physical time to advance. |
104
+
|`LogicalTimestampAdvanceCount`| Successful allocation decisions that emitted logical time ahead of physical time. |
105
+
|`MaxLogicalDriftMs`| Maximum observed distance between emitted logical time and physical time. |
106
+
|`CasRetryCount`| Failed compare-exchange attempts in the lock-free allocation loop. |
107
+
|`RandomBufferRefillCount`| Thread-local random buffer refills. |
108
+
109
+
Most counters are diagnostic event counts, not rates. For example, a single `NewGuids(span)` call may reserve many UUIDs with one successful allocation decision, so `GeneratedCount` increases by `span.Length` while rollback or drift counters increase once for that reservation.
110
+
71
111
## Custom RNGs and Deterministic Tests
72
112
73
113
Custom RNG injection exists so tests and simulations can replay exact UUID sequences. Clockworks does not ship a deterministic RNG implementation; provide your own test-only `RandomNumberGenerator` when you need replay.
@@ -162,3 +202,5 @@ dotnet run --project demo/Clockworks.Demo -- uuidv7-sortability
162
202
# Benchmark mode
163
203
dotnet run --project demo/Clockworks.Demo -- uuidv7 --bench
164
204
```
205
+
206
+
Benchmark mode includes a side-by-side single-threaded comparison of the default hot path and statistics-enabled hot path.
0 commit comments