Skip to content

Proposal: clock-drift correction, potentially with opt-in #206

@noamr

Description

@noamr

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:

  1. Add a clockOffset or drift or so to performance timeline entries and let users of the API correct the clocks themselves if they wish.
  2. Automatically align entries to the wall clock (while maintaining purely monotonic deltas inside an entry)
  3. Make this an opt-in for getEntries{ByFoo} functions or for performance observers.

/cc @yoavweiss @jyasskin @nicjansma

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions