Skip to content

ksuidms: change to 4ms increments#31

Merged
svix-jbrown merged 1 commit into
mainfrom
jbrown/4ms
Mar 13, 2026
Merged

ksuidms: change to 4ms increments#31
svix-jbrown merged 1 commit into
mainfrom
jbrown/4ms

Conversation

@svix-jbrown
Copy link
Copy Markdown
Contributor

Currently, KsuidMs treats the fractional part as being 1/256th of a second (roughly 3.9ms). This does not match our rust implementation, nor the documentation comments, which describe it as having 4ms of precision.

To wit, on Rust the KSUID 3AsgpMQps5Gm44a7CdiFOrApblU (whose fifth byte is 0x80) corresponds to the timestamp 1773386873.512, and on the current release of this library, it corresponds to 1773386873.500. This also matches the rust behavior of having the millisecond part of ksuids whose fifth byte is in the range 0xf9-0xff wrap around to the beginning of the second.

This is a breaking change, obviously.

Other changes in here:

  • Removed an import call inside a hot function (what a silly thing to do!)
  • Stopped initializing a new ksuid with now() on every .from_base62 parse and then immediately throwing it away
  • Rewrote tests to use test vectors / pytest.mark.parametrize
  • Made test_ms_mode_datetime cover a lot more cases

@svix-jbrown svix-jbrown merged commit 2831a15 into main Mar 13, 2026
2 checks passed
@svix-jbrown svix-jbrown deleted the jbrown/4ms branch March 13, 2026 17:06
svix-jbrown added a commit that referenced this pull request Mar 13, 2026
@svix-jbrown svix-jbrown mentioned this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants