uuid-rs / uuid

Generate and parse UUIDs.
https://www.crates.io/crates/uuid
Other
1.01k stars 192 forks source link

Avoid taking the shared lock when getting usable bits in Uuid::now_v7 #762

Closed KodrAus closed 4 months ago

KodrAus commented 4 months ago

We previously would take the global lock when getting the number of bits the counter occupies in Uuid::now_v7(), despite this value being a constant.

As expected, it does reduce the cost of Uuid::now_v7(). On my M1 MacBook Pro:

Before:

test now_v7            ... bench:          61.51 ns/iter (+/- 0.83)

After:

test now_v7            ... bench:          55.67 ns/iter (+/- 2.43)