Bug 258572 - performance.timeOrigin drifts slowly during the lifetime of a page
Summary: performance.timeOrigin drifts slowly during the lifetime of a page
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: Safari 16
Hardware: Mac (Apple Silicon) macOS 12
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-06-27 07:41 PDT by Nic Jansma
Modified: 2023-07-04 07:41 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nic Jansma 2023-06-27 07:41:00 PDT
Accessing performance.timeOrigin repeatedly during the lifetime of a page shows that it drifts slowly.

For example, when I first load a page and query performance.timeOrigin I get:

> [new Date, performance.timeOrigin]
< [Tue Jun 27 2023 07:34:57 GMT-0700 (Pacific Daylight Time), 1687876483498.0002]

Then, a few minutes later when I'm querying the same API, I get:

> [new Date, performance.timeOrigin]
< [Tue Jun 27 2023 07:35:37 GMT-0700 (Pacific Daylight Time), 1687876483497]

In this case, it went "backwards" by 1.0002 ms.

Then again a minute later:

> [new Date, performance.timeOrigin]
< [Tue Jun 27 2023 07:36:56 GMT-0700 (Pacific Daylight Time), 1687876483494]

In this case, it went "backwards" by 3ms.

In other instances, I've seen the time drift "forward" slowly over time[1].

timeOrigin should not be changing during the lifetime of the page.

[1] https://docs.google.com/presentation/d/1RW_fLZwUevn7IBXE3hFvKMnaEBs83Dxp3_yLflEfAXk/edit#slide=id.g22706244ab9_0_111
Comment 1 Noam Rosenthal 2023-06-29 02:40:26 PDT
I double-checked the spec, and indeed it should be stable throughout the lifetime of the document.
In https://w3c.github.io/hr-time/#dfn-estimated-monotonic-time-of-the-unix-epoch, the "estimated monotonic time of the Unix epoch" is initialized once, while in https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/Performance.cpp#L86 it's effectively computed every time timeOrigin() is called.
Comment 2 Radar WebKit Bug Importer 2023-07-04 07:41:14 PDT
<rdar://problem/111742735>