Bug 1325467 - Part 3: Add a pref for adjusting the minimum timeout for tracking timeouts; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 21 Dec 2016 22:56:45 -0500
changeset 329767 eca0ecd94ddc35b77f6c9b520f3196464abb727d
parent 329766 ae1b2492b2fce313ad59d594d4e3cc3d41aad879
child 329768 0bf730c7d8cb01d0c8474d71dfffa84849c6d2be
push id85804
push usereakhgari@mozilla.com
push dateWed, 18 Jan 2017 02:01:29 +0000
treeherdermozilla-inbound@eca0ecd94ddc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1325467
milestone53.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 1325467 - Part 3: Add a pref for adjusting the minimum timeout for tracking timeouts; r=bkelly These prefs allow us to customize the treatment for foreground and background tabs. By default these timeouts aren't treated differently.
dom/base/TimeoutManager.cpp
--- a/dom/base/TimeoutManager.cpp
+++ b/dom/base/TimeoutManager.cpp
@@ -15,28 +15,35 @@
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static int32_t              gRunningTimeoutDepth       = 0;
 
 // The default shortest interval/timeout we permit
 #define DEFAULT_MIN_TIMEOUT_VALUE 4 // 4ms
 #define DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE 1000 // 1000ms
-static int32_t gMinTimeoutValue;
-static int32_t gMinBackgroundTimeoutValue;
+#define DEFAULT_MIN_TRACKING_TIMEOUT_VALUE 4 // 4ms
+#define DEFAULT_MIN_TRACKING_BACKGROUND_TIMEOUT_VALUE 1000 // 1000ms
+static int32_t gMinTimeoutValue = 0;
+static int32_t gMinBackgroundTimeoutValue = 0;
+static int32_t gMinTrackingTimeoutValue = 0;
+static int32_t gMinTrackingBackgroundTimeoutValue = 0;
 int32_t
 TimeoutManager::DOMMinTimeoutValue(bool aIsTracking) const {
   // First apply any back pressure delay that might be in effect.
   int32_t value = std::max(mBackPressureDelayMS, 0);
   // Don't use the background timeout value when there are audio contexts
   // present, so that background audio can keep running smoothly. (bug 1181073)
   bool isBackground = !mWindow.AsInner()->HasAudioContexts() &&
     mWindow.IsBackgroundInternal();
-  return
-    std::max(isBackground ? gMinBackgroundTimeoutValue : gMinTimeoutValue, value);
+  auto minValue = aIsTracking ? (isBackground ? gMinTrackingBackgroundTimeoutValue
+                                              : gMinTrackingTimeoutValue)
+                              : (isBackground ? gMinBackgroundTimeoutValue
+                                              : gMinTimeoutValue);
+  return std::max(minValue, value);
 }
 
 #define TRACKING_SEPARATE_TIMEOUT_BUCKETING_STRATEGY 0 // Consider all timeouts coming from tracking scripts as tracking
 // These strategies are useful for testing.
 #define ALL_NORMAL_TIMEOUT_BUCKETING_STRATEGY        1 // Consider all timeouts as normal
 #define ALTERNATE_TIMEOUT_BUCKETING_STRATEGY         2 // Put every other timeout in the list of tracking timeouts
 #define RANDOM_TIMEOUT_BUCKETING_STRATEGY            3 // Put timeouts into either the normal or tracking timeouts list randomly
 static int32_t gTimeoutBucketingStrategy = 0;
@@ -115,16 +122,22 @@ void
 TimeoutManager::Initialize()
 {
   Preferences::AddIntVarCache(&gMinTimeoutValue,
                               "dom.min_timeout_value",
                               DEFAULT_MIN_TIMEOUT_VALUE);
   Preferences::AddIntVarCache(&gMinBackgroundTimeoutValue,
                               "dom.min_background_timeout_value",
                               DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE);
+  Preferences::AddIntVarCache(&gMinTrackingTimeoutValue,
+                              "dom.min_tracking_timeout_value",
+                              DEFAULT_MIN_TRACKING_TIMEOUT_VALUE);
+  Preferences::AddIntVarCache(&gMinTrackingBackgroundTimeoutValue,
+                              "dom.min_tracking_background_timeout_value",
+                              DEFAULT_MIN_BACKGROUND_TIMEOUT_VALUE);
   Preferences::AddIntVarCache(&gTimeoutBucketingStrategy,
                               "dom.timeout_bucketing_strategy",
                               TRACKING_SEPARATE_TIMEOUT_BUCKETING_STRATEGY);
 }
 
 uint32_t
 TimeoutManager::GetTimeoutId(Timeout::Reason aReason)
 {