[Webkit-unassigned] [Bug 225610] New: performance.now() does not tick during system sleep

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon May 10 13:44:52 PDT 2021


https://bugs.webkit.org/show_bug.cgi?id=225610

            Bug ID: 225610
           Summary: performance.now() does not tick during system sleep
           Product: WebKit
           Version: Safari 14
          Hardware: Mac (Intel)
                OS: macOS 11
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Platform
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: webkit-bugzilla at mayerware.com

Steps to Reproduce
------------------
1. Open a tab and navigate to a page. Open the console and compute the difference between the system clock and the document's monotonic clock (Date.now() -  performance.timing.navigationStart - performance.now()).
2. Put the system to sleep for a period of time, then wake the system.
3. For the same page, recompute the difference between the system clock and the document's monotonic clock.

Expected Result
---------------
The difference between the system clock and the document's monotonic clock should be about the same before and after sleep, because the monotonic clock continued to (logically) tick during sleep.

The original W3C High Resolution Time spec, which WebKit fully implements, did not address monotonic clock behavior during sleep. The newer Level 2 spec, which WebKit partially implements, indicates that monotonic clocks should continue to tick during sleep. See: https://github.com/mdn/content/issues/4713

Actual Result
-------------
The difference between the system clock and the document's monotonic clock is approximately the duration of the system sleep, because the monotonic clock froze during sleep.

The cause of the issue appears to be the choice of operating system clock API:
https://github.com/WebKit/WebKit/blob/79daff42b19103a15340e4005ac90facf1fc46c9/Source/WebCore/page/Performance.cpp#L75
https://github.com/WebKit/WebKit/blob/79daff42b19103a15340e4005ac90facf1fc46c9/Source/WTF/wtf/CurrentTime.cpp#L268

MonotonicTime::now() currently uses the following clocks:
* GLib: g_get_monotonic_time(), which may or may not tick during sleep (either is specifically permitted), and which may or may not be subject to clock adjustments that are monotonic and small/gradual (unspecified).
* Darwin: mach_absolute_time(), which does not tick during sleep, and which is not subject to any clock adjustments.
* Fuchsia: zx_clock_get_monotonic(), which does not tick during sleep (current behavior but documentation notes this is unsettled), and which may or may not be subject to clock adjustments that are monotonic and small/gradual (unspecified).
* Linux: clock_gettime() with CLOCK_MONOTONIC, which does not tick during sleep, and which may be subject to clock adjustments that are monotonic and small/gradual.
* BSD: clock_gettime() with CLOCK_MONOTONIC, which does tick during sleep, and which may be subject to clock adjustments that are monotonic and small/gradual.

The right clocks, at least for performance.now() purposes, probably are:
* GLib: there is no clock that ticks during sleep, so fall back to the operating system clock.
* Darwin: clock_gettime() with CLOCK_MONOTONIC (same sleep and adjustment behavior as BSD above).
* Fuchsia: there is no clock that ticks during sleep... zx_clock_get_monotonic() is the only option.
* Linux: clock_gettime() with CLOCK_BOOTTIME (same as BSD above).
* BSD: same as above.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20210510/2da35161/attachment-0001.htm>


More information about the webkit-unassigned mailing list