Bug 1559563 - P2. Small optimization of `Once` StaticPrefs accessor. r=njn
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 18 Jun 2019 11:26:25 +0000
changeset 479162 5f0f3775605323d865539da3a7c4cb3d1fd36ff2
parent 479161 535345f0ff55c22fe512ea1cae5e7cb29378601d
child 479163 82a145adddad6ef0a8434fd25e049c60a3b87276
child 479164 674aabaec2c45fbec631dde9d1d65456924b2dc1
push id36170
push usercbrindusan@mozilla.com
push dateWed, 19 Jun 2019 03:56:45 +0000
treeherdermozilla-central@5f0f37756053 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1559563
milestone69.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 1559563 - P2. Small optimization of `Once` StaticPrefs accessor. r=njn We can avoid testing if we are running in the parent process. Differential Revision: https://phabricator.services.mozilla.com/D35125
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -5390,18 +5390,19 @@ static void InitVarCachePref(StaticPrefs
       MOZ_LIKELY(aIsStartup)) {
     AddVarCache(aCache, aName, aDefaultValue, true);
   }
 }
 
 static Atomic<bool> sOncePrefRead(false);
 static StaticMutex sOncePrefMutex;
 
-/* static */ void StaticPrefs::MaybeInitOncePrefs() {
-  if (!XRE_IsParentProcess() || sOncePrefRead) {
+/* static */
+void StaticPrefs::MaybeInitOncePrefs() {
+  if (MOZ_LIKELY(sOncePrefRead)) {
     // `Once` StaticPrefs have already been initialized to their default value.
     return;
   }
   StaticMutexAutoLock lock(sOncePrefMutex);
   if (NS_IsMainThread()) {
     InitOncePrefs();
   } else {
     RefPtr<Runnable> runnable = NS_NewRunnableFunction(
@@ -5671,16 +5672,20 @@ void StaticPrefs::InitStaticPrefsFromSha
       rv = PreferencesInternalMethods::GetSharedPrefValue(name, &val); \
     }                                                                  \
     MOZ_DIAGNOSTIC_ALWAYS_TRUE(NS_SUCCEEDED(rv));                      \
     StaticPrefs::sVarCache_##id = val;                                 \
   }
 #include "mozilla/StaticPrefList.h"
 #undef PREF
 #undef VARCACHE_PREF
+  // `Once` StaticPrefs have been set to their value in the step above and
+  // outside the parent process they are immutable. So we set sOncePrefRead
+  // so that we can directly skip any lazy initializations.
+  sOncePrefRead = true;
 }
 
 }  // namespace mozilla
 
 #undef ENSURE_PARENT_PROCESS
 
 //===========================================================================
 // Module and factory stuff