cujojs / most

Ultra-high performance reactive programming
MIT License
3.49k stars 231 forks source link

Date.now isn't monotonic #452

Closed frangio closed 7 years ago

frangio commented 7 years ago

The default timer uses Date.now to get a timestamp, which is not monotonic like the Architecture document says it should be.

In the browser there's a performance.now method that is more precise and, as far as I can tell, guaranteed to be monotonic.

It's not available in Node.js. I'm not sure if most supports platforms other than the browser, but in that case the performance-now package on npm provides a cross-platform solution falling back to a native monotonic Node.js function or even Date.now if nothing else is available.

briancavalier commented 7 years ago

Thanks @frangio. Yes, you're right.

While Date.now has been "monotonic enough" in practice, any change to the system clock while an app is running would likely cause some chaos. I think we could make a change like this for 2.0 (work is ongoing here in @most/core)). Coincidentally, we've already been discussing switching to relative time rather than absolute system clock time, so switching to a truly monotonic time source would fit well with that.

briancavalier commented 7 years ago

I'm not sure if most supports platforms other than the browser

Yep, it does. It supports Node and browsers.

briancavalier commented 7 years ago

@frangio We're tracking this in https://github.com/mostjs/core/issues/62 now. Closing this one. Thanks again!

frangio commented 7 years ago

Great!