blacktip
blacktip copied to clipboard
Making getting the current time faster
This sucks: https://github.com/bitemyapp/blacktip/blob/master/src/Database/Blacktip.hs#L45
Worse, it sucks in multiple ways.
First:
(round . (*1000))
round
is slow-as. The (*1000)
ideally wouldn't even be necessary.
Second:
PSX.getPOSIXTime
originates in a syscall and goes through like 3 redundant transformations before I get anything out of it. This is slow and unnecessary! Ideally we'd want a millisecond-resolution with the same 64-bit representation in as little work as is possible.
Worth noting that getPOSIXTime doesn't guarantee monotonicity. I don't know how likely of a problem that is.
The clock package is probably a better fit for this than the time
package.
@andrewthad yeah somebody mentioned it had monotonic clock but there's still some trickiness involved:
-
I'd still want to cache it (millisecond resolution?) so I'm not pinging the kernel over and over
-
I need to peg the monotonic clock against wall clock so that I know what arithmetic to do to get the nominal epoch time for each id
Both good points. The caching problem seems like something auto-update handles, but the way I've seen it used in yesod, it typically operates at the one-second resolution, not at the one-millisecond resolution. I don't really know exactly how much overhead it adds.
I remember it from mucking around in Yesod, I need to get around to reviewing auto-update's code.
@andrewthad what's your interest in this repo?
I need to quit using Elasticsearch's autogenerated IDs and I like flake IDs.
@andrewthad I edited your comment, is that about right? If so, I think this is a reasonable use-case. It's definitely a good idea to get off of Elasticsearch's auto-generated ids. Are you planning to PR some last mile production readiness stuff?
Yeah, that's about what I meant. I'll try to put together a PR soon.
@andrewthad Aight, Imma clean house a little then.
Edit: Done, cleaned up the build. Let me know if you have questions.