Bug 1414150 - Remove the "idle_queue.*" prefs. r=farre.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 08 Nov 2017 07:54:16 +1100
changeset 390703 dd6063357ae629ffb82e2087ac58431c07548a82
parent 390702 242b1157a36a8fbe769179a630c8457562d9568f
child 390704 35a375648ee0224743657c67edfebf0cbe81b719
push id32839
push usernbeleuzu@mozilla.com
push dateWed, 08 Nov 2017 10:51:56 +0000
treeherdermozilla-central@f63559d7e6a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1414150
milestone58.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 1414150 - Remove the "idle_queue.*" prefs. r=farre. There's no good reason why these can't be code constants. Especially given that, due to a bug, changes to the "idle_queue.{min,long}_period" constants were not being passed onto the C++ code! Here's why: those two prefs were specified as integers in all.js. But we used AddFloatVarCache() to set up the reading of those prefs. libpref fakes floats by storing them as strings and then converting them to floats when they are read. Which means that AddFloatVarCache() used to fail to get the value from all.js -- because there's a type mismatch, int vs. string -- and instead use the fallback default. That value is the same as the one in all.js, which is lucky. But if someone changed the value in about:config to 100 (an integer), a similar failure would have occured and the value used by the C++ code wouldn't be updated! Also note that idle_queue.max_timer_thread_bound did not have a value in all.js. What a mess!
modules/libpref/init/all.js
xpcom/threads/MainThreadIdlePeriod.cpp
xpcom/threads/MainThreadIdlePeriod.h
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -3208,43 +3208,32 @@ pref("dom.max_script_run_time", 10);
 pref("dom.max_ext_content_script_run_time", 5);
 
 // Stop all scripts in a compartment when the "stop script" dialog is used.
 pref("dom.global_stop_script", true);
 
 // Time (milliseconds) between throttled idle callbacks.
 pref("dom.idle_period.throttled_length", 10000);
 
-// The amount of idle time (milliseconds) reserved for a long idle period
-pref("idle_queue.long_period", 50);
-
 // Support the input event queue on the main thread of content process
 pref("input_event_queue.supported", true);
 
 // The maximum and minimum time (milliseconds) we reserve for handling input
 // events in each frame.
 pref("input_event_queue.duration.max", 8);
 pref("input_event_queue.duration.min", 1);
 
 // The default amount of time (milliseconds) required for handling a input
 // event.
 pref("input_event_queue.default_duration_per_event", 1);
 
 // The number of processed input events we use to predict the amount of time
 // required to process the following input events.
 pref("input_event_queue.count_for_prediction", 9);
 
-// The minimum amount of time (milliseconds) required for an idle
-// period to be scheduled on the main thread. N.B. that
-// layout.idle_period.time_limit adds padding at the end of the idle
-// period, which makes the point in time that we expect to become busy
-// again be:
-// now + idle_queue.min_period + layout.idle_period.time_limit
-pref("idle_queue.min_period", 3);
-
 // Hang monitor timeout after which we kill the browser, in seconds
 // (0 is disabled)
 // Disabled on all platforms per bug 705748 until the found issues are
 // resolved.
 pref("hangmonitor.timeout", 0);
 
 pref("plugins.load_appdir_plugins", false);
 // If true, plugins will be click to play
--- a/xpcom/threads/MainThreadIdlePeriod.cpp
+++ b/xpcom/threads/MainThreadIdlePeriod.cpp
@@ -6,96 +6,58 @@
 
 #include "MainThreadIdlePeriod.h"
 
 #include "mozilla/Maybe.h"
 #include "mozilla/Preferences.h"
 #include "nsRefreshDriver.h"
 #include "nsThreadUtils.h"
 
-#define DEFAULT_LONG_IDLE_PERIOD 50.0f
-#define DEFAULT_MIN_IDLE_PERIOD 3.0f
-#define DEFAULT_MAX_TIMER_THREAD_BOUND 5
+// The amount of idle time (milliseconds) reserved for a long idle period.
+static const double kLongIdlePeriodMS = 50.0;
 
-const uint32_t kMaxTimerThreadBoundClamp = 15;
+// The minimum amount of time (milliseconds) required for an idle period to be
+// scheduled on the main thread. N.B. layout.idle_period.time_limit adds
+// padding at the end of the idle period, which makes the point in time that we
+// expect to become busy again be:
+//   now + kMinIdlePeriodMS + layout.idle_period.time_limit
+static const double kMinIdlePeriodMS = 3.0;
+
+static const uint32_t kMaxTimerThreadBound = 5;       // milliseconds
+static const uint32_t kMaxTimerThreadBoundClamp = 15; // milliseconds
 
 namespace mozilla {
 
 NS_IMETHODIMP
 MainThreadIdlePeriod::GetIdlePeriodHint(TimeStamp* aIdleDeadline)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aIdleDeadline);
 
   TimeStamp now = TimeStamp::Now();
   TimeStamp currentGuess =
-    now + TimeDuration::FromMilliseconds(GetLongIdlePeriod());
+    now + TimeDuration::FromMilliseconds(kLongIdlePeriodMS);
 
   currentGuess = nsRefreshDriver::GetIdleDeadlineHint(currentGuess);
-  currentGuess = NS_GetTimerDeadlineHintOnCurrentThread(currentGuess, GetMaxTimerThreadBound());
+  currentGuess = NS_GetTimerDeadlineHintOnCurrentThread(currentGuess, kMaxTimerThreadBound);
 
   // If the idle period is too small, then just return a null time
   // to indicate we are busy. Otherwise return the actual deadline.
   TimeDuration minIdlePeriod =
-    TimeDuration::FromMilliseconds(GetMinIdlePeriod());
+    TimeDuration::FromMilliseconds(kMinIdlePeriodMS);
   bool busySoon = currentGuess.IsNull() ||
                   (now >= (currentGuess - minIdlePeriod)) ||
                   currentGuess < mLastIdleDeadline;
 
   if (!busySoon) {
     *aIdleDeadline = mLastIdleDeadline = currentGuess;
   }
 
   return NS_OK;
 }
 
 /* static */ float
 MainThreadIdlePeriod::GetLongIdlePeriod()
 {
-  MOZ_ASSERT(NS_IsMainThread());
-
-  static float sLongIdlePeriod = DEFAULT_LONG_IDLE_PERIOD;
-  static bool sInitialized = false;
-
-  if (!sInitialized && Preferences::IsServiceAvailable()) {
-    sInitialized = true;
-    Preferences::AddFloatVarCache(&sLongIdlePeriod, "idle_queue.long_period",
-                                  DEFAULT_LONG_IDLE_PERIOD);
-  }
-
-  return sLongIdlePeriod;
-}
-
-/* static */ float
-MainThreadIdlePeriod::GetMinIdlePeriod()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  static float sMinIdlePeriod = DEFAULT_MIN_IDLE_PERIOD;
-  static bool sInitialized = false;
-
-  if (!sInitialized && Preferences::IsServiceAvailable()) {
-    sInitialized = true;
-    Preferences::AddFloatVarCache(&sMinIdlePeriod, "idle_queue.min_period",
-                                  DEFAULT_MIN_IDLE_PERIOD);
-  }
-
-  return sMinIdlePeriod;
-}
-
-/* static */ uint32_t
-MainThreadIdlePeriod::GetMaxTimerThreadBound()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  static uint32_t sMaxTimerThreadBound = DEFAULT_MAX_TIMER_THREAD_BOUND;
-  static bool sInitialized = false;
-
-  if (!sInitialized && Preferences::IsServiceAvailable()) {
-    sInitialized = true;
-    Preferences::AddUintVarCache(&sMaxTimerThreadBound, "idle_queue.max_timer_thread_bound",
-                                 DEFAULT_MAX_TIMER_THREAD_BOUND);
-  }
-
-  return std::max(sMaxTimerThreadBound, kMaxTimerThreadBoundClamp);
+  return kLongIdlePeriodMS;
 }
 
 } // namespace mozilla
--- a/xpcom/threads/MainThreadIdlePeriod.h
+++ b/xpcom/threads/MainThreadIdlePeriod.h
@@ -18,18 +18,17 @@ public:
   NS_DECL_NSIIDLEPERIOD
 
   MainThreadIdlePeriod()
     : mLastIdleDeadline(TimeStamp::Now())
   {
   }
 
   static float GetLongIdlePeriod();
-  static float GetMinIdlePeriod();
-  static uint32_t GetMaxTimerThreadBound();
+
 private:
   virtual ~MainThreadIdlePeriod() {}
 
   TimeStamp mLastIdleDeadline;
 };
 
 } // namespace mozilla