-
Notifications
You must be signed in to change notification settings - Fork 26
Description
The problem:
The monotonic clock is accurate for short measurements. But as time goes by, e.g. in long-session web apps, it slowly starts to be less and less aligned with the wall clock. The problem exacerbates when the system throttles or pauses the monotonic clock when a process sleeps. This means that the equation performance.timeOrigin + performance.now() === new Date() becomes less and less reliable over time.
See w3c/hr-time#141 and several related discussions.
The proposal:
Compute a clock offset value per performance entry, at the time of adding the entry to the timeline. This would be something along the lines of clockOffset = new Date() - performance.timeOrigin - performance.now(). This value can help produce wall-clock-aligned timeline out of the standard monotonic-based timeline. The differences between values inside an entry would remain monotonically aligned with each other.
This keeps the benefit of monotonic clocks: accurate offsets, while mitigating the main issue with it: drift from the wall clock.
We can use this offset in several ways, that are somewhat interchangeable/bikesheddable:
- Add a
clockOffsetordriftor so to performance timeline entries and let users of the API correct the clocks themselves if they wish. - Automatically align entries to the wall clock (while maintaining purely monotonic deltas inside an entry)
- Make this an opt-in for
getEntries{ByFoo}functions or for performance observers.