blacktip icon indicating copy to clipboard operation
blacktip copied to clipboard

Making getting the current time faster

Open bitemyapp opened this issue 9 years ago • 8 comments

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.

bitemyapp avatar Oct 09 '14 04:10 bitemyapp

The clock package is probably a better fit for this than the time package.

andrewthad avatar Jun 15 '17 13:06 andrewthad

@andrewthad yeah somebody mentioned it had monotonic clock but there's still some trickiness involved:

  1. I'd still want to cache it (millisecond resolution?) so I'm not pinging the kernel over and over

  2. 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

bitemyapp avatar Jun 15 '17 15:06 bitemyapp

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.

andrewthad avatar Jun 15 '17 15:06 andrewthad

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?

bitemyapp avatar Jun 15 '17 15:06 bitemyapp

I need to quit using Elasticsearch's autogenerated IDs and I like flake IDs.

andrewthad avatar Jun 15 '17 18:06 andrewthad

@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?

bitemyapp avatar Jun 15 '17 18:06 bitemyapp

Yeah, that's about what I meant. I'll try to put together a PR soon.

andrewthad avatar Jun 15 '17 20:06 andrewthad

@andrewthad Aight, Imma clean house a little then.

Edit: Done, cleaned up the build. Let me know if you have questions.

bitemyapp avatar Jun 15 '17 21:06 bitemyapp