On Mon, 19 May 2025 18:17:09 GMT, Roger Riggs <rri...@openjdk.org> wrote:
> Can the sub-microsecond value just be truncated and avoid the expensive > divide operation?' method 3 of secion 6.2 of https://www.rfc-editor.org/rfc/rfc9562.html#name-monotonicity-and-counters states > start with the portion of the timestamp expressed as a fraction of the > clock's tick value (fraction of a millisecond for UUIDv7). Compute the count > of possible values that can be represented in the available bit space, 4096 > for the UUIDv7 rand_a field. Using floating point or scaled integer > arithmetic, multiply this fraction of a millisecond value by 4096 and round > down (toward zero) to an integer result to arrive at a number between 0 and > the maximum allowed for the indicated bits, which sorts monotonically based > on time. ' so i think we might have to keep the division? though i re-shuffled the equation to `int nsBits = (int) ((nsTime % 1_000_000) / 1_000_000.0 * 4096);` which gives scaled integer division rather than floating point and gave a very slight imporved perfomance to 143.758 ± 2.135 ns/op ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25303#discussion_r2097994819