Title: [281879] trunk/Source/WebCore
Revision
281879
Author
[email protected]
Date
2021-09-01 14:34:59 -0700 (Wed, 01 Sep 2021)

Log Message

Improve time precision when cross-origin isolated via COOP+COEP
https://bugs.webkit.org/show_bug.cgi?id=228137
<rdar://problem/81197138>

Reviewed by Ryosuke Niwa.

Increase the precision of our high precision time (used by performance.now()) from
1ms to 20us when cross-origin isolated via COOP=same-origin + COEP=require-corp.
Precision remains the same (1ms) when not cross-origin isolated.

This aligns our behavior with Firefox.

Note that Chrome provides higher precision (100us in general and 5us when
cross-origin-isolated).

* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::setCrossOriginMode):
* page/Performance.cpp:
(WebCore::Performance::reduceTimeResolution):
(WebCore::Performance::allowHighPrecisionTime):
* page/Performance.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281878 => 281879)


--- trunk/Source/WebCore/ChangeLog	2021-09-01 21:30:55 UTC (rev 281878)
+++ trunk/Source/WebCore/ChangeLog	2021-09-01 21:34:59 UTC (rev 281879)
@@ -1,3 +1,27 @@
+2021-09-01  Chris Dumez  <[email protected]>
+
+        Improve time precision when cross-origin isolated via COOP+COEP
+        https://bugs.webkit.org/show_bug.cgi?id=228137
+        <rdar://problem/81197138>
+
+        Reviewed by Ryosuke Niwa.
+
+        Increase the precision of our high precision time (used by performance.now()) from
+        1ms to 20us when cross-origin isolated via COOP=same-origin + COEP=require-corp.
+        Precision remains the same (1ms) when not cross-origin isolated.
+
+        This aligns our behavior with Firefox.
+
+        Note that Chrome provides higher precision (100us in general and 5us when
+        cross-origin-isolated).
+
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::setCrossOriginMode):
+        * page/Performance.cpp:
+        (WebCore::Performance::reduceTimeResolution):
+        (WebCore::Performance::allowHighPrecisionTime):
+        * page/Performance.h:
+
 2021-09-01  Ryosuke Niwa  <[email protected]>
 
         Eagerly resolve slot elements to simply the code in SlotAssignment

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (281878 => 281879)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-09-01 21:30:55 UTC (rev 281878)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-09-01 21:34:59 UTC (rev 281879)
@@ -47,6 +47,7 @@
 #include "MessagePort.h"
 #include "Navigator.h"
 #include "Page.h"
+#include "Performance.h"
 #include "PublicURLManager.h"
 #include "RejectedPromiseTracker.h"
 #include "ResourceRequest.h"
@@ -628,6 +629,8 @@
 void ScriptExecutionContext::setCrossOriginMode(CrossOriginMode crossOriginMode)
 {
     globalCrossOriginMode = crossOriginMode;
+    if (crossOriginMode == CrossOriginMode::Isolated)
+        Performance::allowHighPrecisionTime();
 }
 
 CrossOriginMode ScriptExecutionContext::crossOriginMode()

Modified: trunk/Source/WebCore/page/Performance.cpp (281878 => 281879)


--- trunk/Source/WebCore/page/Performance.cpp	2021-09-01 21:30:55 UTC (rev 281878)
+++ trunk/Source/WebCore/page/Performance.cpp	2021-09-01 21:34:59 UTC (rev 281879)
@@ -58,6 +58,9 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Performance);
 
+constexpr Seconds highTimePrecision { 20_us };
+static Seconds timePrecision { 1_ms };
+
 Performance::Performance(ScriptExecutionContext* context, MonotonicTime timeOrigin)
     : ContextDestructionObserver(context)
     , m_resourceTimingBufferFullTimer(*this, &Performance::resourceTimingBufferFullTimerFired) // FIXME: Migrate this to the event loop as well. https://bugs.webkit.org/show_bug.cgi?id=229044
@@ -92,11 +95,16 @@
 
 Seconds Performance::reduceTimeResolution(Seconds seconds)
 {
-    double resolution = (1000_us).seconds();
+    double resolution = timePrecision.seconds();
     double reduced = std::floor(seconds.seconds() / resolution) * resolution;
     return Seconds(reduced);
 }
 
+void Performance::allowHighPrecisionTime()
+{
+    timePrecision = highTimePrecision;
+}
+
 DOMHighResTimeStamp Performance::relativeTimeFromTimeOriginInReducedResolution(MonotonicTime timestamp) const
 {
     Seconds seconds = timestamp - m_timeOrigin;

Modified: trunk/Source/WebCore/page/Performance.h (281878 => 281879)


--- trunk/Source/WebCore/page/Performance.h	2021-09-01 21:30:55 UTC (rev 281878)
+++ trunk/Source/WebCore/page/Performance.h	2021-09-01 21:34:59 UTC (rev 281879)
@@ -106,6 +106,7 @@
     void registerPerformanceObserver(PerformanceObserver&);
     void unregisterPerformanceObserver(PerformanceObserver&);
 
+    static void allowHighPrecisionTime();
     static Seconds reduceTimeResolution(Seconds);
 
     DOMHighResTimeStamp relativeTimeFromTimeOriginInReducedResolution(MonotonicTime) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to