jimn
10/12/2021, 3:13 PMInstant
ctor, and serialization, we need 12 bytes, a long for ms and int for nanos.
The kotlin Duration
analog class only appears to support at best a Long or Double, neither which supports the same resolution. Instead of a break between Java's Date, DateTime, and Instant classes which supports DateTimes with nanosecond backingstores, Duration apparently presumes to do all three and for events on astronomical scales of time resolution appears to force the coder to box a relative 64 bit expanse of measurement for the non-jvm stdlib.
to my understanding BigInteger math is a sliding set of 32 bit Int operations going up and down to MAXINT resolution and is claimed to be faster in the C2 on intel than native wide instructions in some cases.
Is Duration with a promotion option to BigInteger backingstore reasonable?
The solution would address
a) usecases that want higher res, and
b) a sideload BitSet/BigInt serialization option that can match impedences with e.g. Instance and other DateTime libraries which don't all apparently assume 64 bits and only 64 bits.ilya.gorbunov
10/12/2021, 5:11 PMInstant
from Long
number of seconds and Int
number of nanoseconds using this function: https://github.com/Kotlin/kotlinx-datetime/blob/v0.3.0/core/common/src/Instant.kt#L122ilya.gorbunov
10/12/2021, 5:19 PMDuration
from Long seconds/milliseconds + Int nanoseconds, you can just build these parts separately and add them together using plus
operator. However, if the Duration value exceeds 146 years, its precision becomes limited to milliseconds.
In general, we don't recommend using Duration where Instant is required and do not consider such use cases valid for Duration. Therefore, we're not considering promoting the backing property of Duration to BigInteger either.jimn
10/12/2021, 6:50 PMjimn
10/12/2021, 6:51 PM