Crates.io | re_tuid |
lib.rs | re_tuid |
version | 0.19.1 |
source | src |
created_at | 2023-02-12 16:22:10.972204 |
updated_at | 2024-11-05 10:51:09.18886 |
description | 128-bit Time-based Unique Identifier |
homepage | https://rerun.io |
repository | https://github.com/rerun-io/rerun |
max_upload_size | |
id | 783296 |
size | 15,780 |
Part of the rerun
family of crates.
TUID:s are 128-bit identifiers, that have a global time-based order, with tie-breaking between threads. This means you can use a TUID as a tie-breaker in time series databases.
TUID is based on two fields, both of which are monotonically increasing:
time_ns: u64
inc: u64
time_ns
is an approximate nanoseconds since unix epoch. It is monotonically increasing, though two TUID:s generated closely together may get the same time_ns
.
inc
is a monotonically increasing integer, initialized to some random number on each thread.
So the algorithm is this:
inc
inc
time_ns
TUID { time_ns, inc }
On a single core of a 2022 M1 MacBook we can generate 40 million TUID/s, which is 25 ns per TUID.
For time-based exploits (like Meltdown/Spectre) time_ns
should probably be rounded to nearest millisecond for sensitive systems. The last ~20 bits of time_ns
can be filled with more randomness to lessen the chance of collisions.