-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can Instant
s be NonZeroU64
?
#64
Comments
Of course, if it's possible for |
Thinking through this one a little bit, and putting my thoughts down in this issue... I think, practically speaking, there is an infinitesimally small chance of generating an There's also the technically-possible-but-highly-unlikely issue of integer overflow/wraparound as we scale up the raw TSC value and then add it to the reference time anchor, bringing it inline with the output you'd get from While we could always construct an |
The other thing is that doing so would introduce a 1ns forward jump about half of the time, which isn't terrible in terms of accuracy, but it might make monotonicity invariants harder to achieve. Gotta think through that one... |
Just to close the mental loop around the bitwise-AND idea for my own sake: I think this would work. Since we're only ever adding to the value, we won't be changing the numbers such that they warp backwards in time, which upholds the monotonicity invariant between two values of I'll whip up a simple PR to benchmark the change. |
Currently,
quanta::Instant
is represented as a singleu64
value. WillInstant
s ever be 0? If we're reasonably confident thatInstant
s with the value 0 will never be generated, we may want to consider changing the internal representation toNonZeroU64
. This will permitOption<Instant>
to be niche optimized into a single 64-bit value.My particular use case for this is that I'd like to be able to store an
Instant
in anAtomicU64
, and some of those instants may be initially unset. With the currentquanta
API, I can implement this myself usingInstant::as_u64
, and using 0 as the unset value in my code.However, my understanding is that, in
quanta
1.0, the intention is to makeInstant
opaque and remove theas_u64
method. This means that it will be necessary to switch tocrossbeam_util
'sAtomicCell
type to storeInstant
s atomically. When usingAtomicCell
with opaqueInstant
types, there's no way to initialize those cells to an "empty" value. I could use a specific "program start time"Instant
as the zero value, but it would have to be passed around to a lot of places, making this code significantly more awkward.Instead, it would be really nice to be able to use
AtomicCell<Option<Instant>>
and have it be lock-free on platforms with 64-bit atomics. This would require thatOption<Instant>
occupy a single 64-bit word, which is only possible ifInstant
is represented asNonZeroU64
.The text was updated successfully, but these errors were encountered: