-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should time origin be defined in terms of a monotonic clock? #21
Comments
I was just walking scenarios with @DLehenbauer on this today before I saw your post. :-) My initial thinking was that this is ok, but I frowned when I hit the same conclusion and declared we would solve it later. Perhaps later is now. Per that logic, wouldn't all contexts associated with a UA need a single cross-context "time origin" to allow for things such as a Push Service Worker starting a Window context? |
You don't necessarily need a single cross-context time origin. What you need is that any time you have two things that might use separate nonotonic clocks you do the following:
I really don't have good answers here so far, especially because I don't know how easy item #1 is across all architectures... |
Oh, and the reason I filed the issue is that the initial implementation of |
@bzbarsky slight tangent, but didn't we say that negative numbers are possible and OK? For example, a message from a shared worker that was already running will result in a negative timestamp; same thing in any case where parent process (e.g. nested workers, iframes) sends a message to a child.. |
Sure. Negative numbers are totally possible here. |
As one option, we could add a note under https://w3c.github.io/hr-time/#monotonic-clock that recommends that the monotonic clocks for each origin are bootstrapped from a global monotonic clock, if available? I think that's a good best practice for where such thing is available.. I'm just not not sure we can make it a MUST due to platform gotchas, etc? |
The returned value is the global time of the "zero time" of the time origin. This allows multiple contexts, each with own time origin, to translate timestamps with sub-millisecond resolution, either by communicating their global time to the other context, or first translating their timestamps against the global time of their time origin. Related discussions in #21 and #22. A polyfill for this is ~: Date.now()-performance.now(), modulo clock skew and adjustments that Date.now() is subject to.
@igrigorik @bzbarsky I generally agree with the note that Ilya is thinking of adding. Boris, was your thinking that this should be required by the spec or is a SHOULD sufficient? |
I don't know. It seems to me that in general our monotonic clock abstraction is super-leaky and doesn't really promise very much in the way of monotonicity except very locally. (This is the super-leaky part.) |
nods... by design, right? As it stands, we guarantee that you get monotonic timestamps within the same time-origin, and in #29 we're making that stronger by introducing the concept of a global monotonic clock (which, btw, also covers what we're discussing here). With that in mind, I suggest we close this issue with no action, and continue in #29? |
That seems reasonable. |
👍 closing. |
The returned value is the global time of the "zero time" of the time origin. This allows multiple contexts, each with own time origin, to translate timestamps with sub-millisecond resolution, either by communicating their global time to the other context, or first translating their timestamps against the global time of their time origin. Related discussions in #21 and #22. A polyfill for this is ~: Date.now()-performance.now(), modulo clock skew and adjustments that Date.now() is subject to.
The way things are defined right now, it's not clear whether "time origin" is recorded via wall clock or a monotonic clock.
If it's via wall clock, then you can end up in a situation like this in a web page:
which seems suboptimal. Seems to me like the same monotonic clock used for performance.now() in general should be used for recording all time origins.
The text was updated successfully, but these errors were encountered: