Bug 1443943 Allow internal callers of performance.now() to opt-out of clamping/jittering r=bholley
authorTom Ritter <tom@mozilla.com>
Fri, 09 Mar 2018 20:12:53 -0600
changeset 408197 ba24b6cd4de975ad4b381e55bb5d83f27822d8ba
parent 408196 8d4312a248ec98f0e8b8bf0413c130b595da3a31
child 408198 ea46c0d873829f9270e55baec11ef0ec979d9985
push id33629
push usershindli@mozilla.com
push dateThu, 15 Mar 2018 09:58:11 +0000
treeherdermozilla-central@68dfe5ee5b80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1443943
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1443943 Allow internal callers of performance.now() to opt-out of clamping/jittering r=bholley PresShell only uses performane.now to track refresh times, and notify internal observers. We can provide more accurate times by not clamping and jittering these numbers. MozReview-Commit-ID: FkDGJhrLeAy
dom/performance/Performance.cpp
dom/performance/Performance.h
layout/base/PresShell.cpp
layout/base/PresShell.h
old mode 100755
new mode 100644
--- a/dom/performance/Performance.cpp
+++ b/dom/performance/Performance.cpp
@@ -86,30 +86,36 @@ Performance::Performance(nsPIDOMWindowIn
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 Performance::~Performance()
 {}
 
 DOMHighResTimeStamp
-Performance::Now() const
+Performance::Now()
 {
-  TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
-  DOMHighResTimeStamp rawTime = duration.ToMilliseconds();
+  DOMHighResTimeStamp rawTime = NowUnclamped();
   if (mSystemPrincipal) {
     return rawTime;
   }
 
   const double maxResolutionMs = 0.020;
   DOMHighResTimeStamp minimallyClamped = floor(rawTime / maxResolutionMs) * maxResolutionMs;
   return nsRFPService::ReduceTimePrecisionAsMSecs(minimallyClamped);
 }
 
 DOMHighResTimeStamp
+Performance::NowUnclamped() const
+{
+  TimeDuration duration = TimeStamp::Now() - CreationTimeStamp();
+  return duration.ToMilliseconds();
+}
+
+DOMHighResTimeStamp
 Performance::TimeOrigin()
 {
   if (!mPerformanceService) {
     mPerformanceService = PerformanceService::GetOrCreate();
   }
 
   MOZ_ASSERT(mPerformanceService);
   DOMHighResTimeStamp rawTimeOrigin = mPerformanceService->TimeOrigin(CreationTimeStamp());
old mode 100755
new mode 100644
--- a/dom/performance/Performance.h
+++ b/dom/performance/Performance.h
@@ -59,17 +59,19 @@ public:
   virtual void GetEntriesByName(const nsAString& aName,
                                 const Optional<nsAString>& aEntryType,
                                 nsTArray<RefPtr<PerformanceEntry>>& aRetval);
 
   virtual PerformanceStorage* AsPerformanceStorage() = 0;
 
   void ClearResourceTimings();
 
-  DOMHighResTimeStamp Now() const;
+  DOMHighResTimeStamp Now();
+
+  DOMHighResTimeStamp NowUnclamped() const;
 
   DOMHighResTimeStamp TimeOrigin();
 
   void Mark(const nsAString& aName, ErrorResult& aRv);
 
   void ClearMarks(const Optional<nsAString>& aName);
 
   void Measure(const nsAString& aName,
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -8618,47 +8618,47 @@ void
 PresShell::WillDoReflow()
 {
   mDocument->FlushUserFontSet();
 
   mPresContext->FlushCounterStyles();
 
   mPresContext->FlushFontFeatureValues();
 
-  mLastReflowStart = GetPerformanceNow();
+  mLastReflowStart = GetPerformanceNowUnclamped();
 }
 
 void
 PresShell::DidDoReflow(bool aInterruptible)
 {
   HandlePostedReflowCallbacks(aInterruptible);
 
   nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell();
   if (docShell) {
-    DOMHighResTimeStamp now = GetPerformanceNow();
+    DOMHighResTimeStamp now = GetPerformanceNowUnclamped();
     docShell->NotifyReflowObservers(aInterruptible, mLastReflowStart, now);
   }
 
   if (sSynthMouseMove) {
     SynthesizeMouseMove(false);
   }
 
   mPresContext->NotifyMissingFonts();
 }
 
 DOMHighResTimeStamp
-PresShell::GetPerformanceNow()
+PresShell::GetPerformanceNowUnclamped()
 {
   DOMHighResTimeStamp now = 0;
 
   if (nsPIDOMWindowInner* window = mDocument->GetInnerWindow()) {
     Performance* perf = window->GetPerformance();
 
     if (perf) {
-      now = perf->Now();
+      now = perf->NowUnclamped();
     }
   }
 
   return now;
 }
 
 void
 PresShell::sReflowContinueCallback(nsITimer* aTimer, void* aPresShell)
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -708,17 +708,17 @@ private:
                                            nsIWidget *aRootWidget);
 
   void SynthesizeMouseMove(bool aFromScroll) override;
 
   PresShell* GetRootPresShell();
 
   nscolor GetDefaultBackgroundColorToDraw();
 
-  DOMHighResTimeStamp GetPerformanceNow();
+  DOMHighResTimeStamp GetPerformanceNowUnclamped();
 
   // The callback for the mPaintSuppressionTimer timer.
   static void sPaintSuppressionCallback(nsITimer* aTimer, void* aPresShell);
 
   // The callback for the mReflowContinueTimer timer.
   static void sReflowContinueCallback(nsITimer* aTimer, void* aPresShell);
   bool ScheduleReflowOffTimer();