Bug 1168606 - Introduce preference for maximum number of extra records to preload, defaulting to 0/off for now. r=ttung,asuth
authorSimon Giesecke <sgiesecke@mozilla.com>
Tue, 05 Nov 2019 14:40:33 +0000
changeset 500616 2f0447b228c762d88198398974e2818c0d3b5dc5
parent 500615 933f3452a368cddf7a67bf71e2956ee7cac9a718
child 500617 89817a19f3b38187bca7eecd50cbf39867c4dad8
push id36768
push usershindli@mozilla.com
push dateTue, 05 Nov 2019 22:07:34 +0000
treeherdermozilla-central@e96c1ca93d25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttung, asuth
bugs1168606
milestone72.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 1168606 - Introduce preference for maximum number of extra records to preload, defaulting to 0/off for now. r=ttung,asuth Differential Revision: https://phabricator.services.mozilla.com/D43466
dom/indexedDB/IndexedDatabaseManager.cpp
dom/indexedDB/IndexedDatabaseManager.h
--- a/dom/indexedDB/IndexedDatabaseManager.cpp
+++ b/dom/indexedDB/IndexedDatabaseManager.cpp
@@ -107,27 +107,31 @@ const uint32_t kDeleteTimeoutMs = 1000;
 // The threshold we use for structured clone data storing.
 // Anything smaller than the threshold is compressed and stored in the database.
 // Anything larger is compressed and stored outside the database.
 const int32_t kDefaultDataThresholdBytes = 1024 * 1024;  // 1MB
 
 // The maximal size of a serialized object to be transfered through IPC.
 const int32_t kDefaultMaxSerializedMsgSize = IPC::Channel::kMaximumMessageSize;
 
+const int32_t kDefaultMaxPreloadExtraRecords = 0;
+
 #define IDB_PREF_BRANCH_ROOT "dom.indexedDB."
 
 const char kTestingPref[] = IDB_PREF_BRANCH_ROOT "testing";
 const char kPrefExperimental[] = IDB_PREF_BRANCH_ROOT "experimental";
 const char kPrefFileHandle[] = "dom.fileHandle.enabled";
 const char kDataThresholdPref[] = IDB_PREF_BRANCH_ROOT "dataThreshold";
 const char kPrefMaxSerilizedMsgSize[] =
     IDB_PREF_BRANCH_ROOT "maxSerializedMsgSize";
 const char kPrefErrorEventToSelfError[] =
     IDB_PREF_BRANCH_ROOT "errorEventToSelfError";
 const char kPreprocessingPref[] = IDB_PREF_BRANCH_ROOT "preprocessing";
+const char kPrefMaxPreloadExtraRecords[] =
+    IDB_PREF_BRANCH_ROOT "maxPreloadExtraRecords";
 
 #define IDB_PREF_LOGGING_BRANCH_ROOT IDB_PREF_BRANCH_ROOT "logging."
 
 const char kPrefLoggingEnabled[] = IDB_PREF_LOGGING_BRANCH_ROOT "enabled";
 const char kPrefLoggingDetails[] = IDB_PREF_LOGGING_BRANCH_ROOT "details";
 
 #if defined(DEBUG) || defined(MOZ_GECKO_PROFILER)
 const char kPrefLoggingProfiler[] =
@@ -143,16 +147,17 @@ Atomic<bool> gInitialized(false);
 Atomic<bool> gClosed(false);
 Atomic<bool> gTestingMode(false);
 Atomic<bool> gExperimentalFeaturesEnabled(false);
 Atomic<bool> gFileHandleEnabled(false);
 Atomic<bool> gPrefErrorEventToSelfError(false);
 Atomic<int32_t> gDataThresholdBytes(0);
 Atomic<int32_t> gMaxSerializedMsgSize(0);
 Atomic<bool> gPreprocessingEnabled(false);
+Atomic<int32_t> gMaxPreloadExtraRecords(0);
 
 void AtomicBoolPrefChangedCallback(const char* aPrefName, void* aBool) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aBool);
 
   *static_cast<Atomic<bool>*>(aBool) = Preferences::GetBool(aPrefName);
 }
 
@@ -178,16 +183,31 @@ void MaxSerializedMsgSizePrefChangeCallb
   MOZ_ASSERT(!strcmp(aPrefName, kPrefMaxSerilizedMsgSize));
   MOZ_ASSERT(!aClosure);
 
   gMaxSerializedMsgSize =
       Preferences::GetInt(aPrefName, kDefaultMaxSerializedMsgSize);
   MOZ_ASSERT(gMaxSerializedMsgSize > 0);
 }
 
+void MaxPreloadExtraRecordsPrefChangeCallback(const char* aPrefName,
+                                              void* aClosure) {
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(!strcmp(aPrefName, kPrefMaxPreloadExtraRecords));
+  MOZ_ASSERT(!aClosure);
+
+  gMaxPreloadExtraRecords =
+      Preferences::GetInt(aPrefName, kDefaultMaxPreloadExtraRecords);
+  MOZ_ASSERT(gMaxPreloadExtraRecords >= 0);
+
+  // TODO: We could also allow setting a negative value to preload all available
+  // records, but this doesn't seem to be too useful in general, and it would
+  // require adaptations in ActorsParent.cpp
+}
+
 }  // namespace
 
 IndexedDatabaseManager::IndexedDatabaseManager()
     : mFileMutex("IndexedDatabaseManager.mFileMutex"),
       mBackgroundActor(nullptr) {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
@@ -280,16 +300,19 @@ nsresult IndexedDatabaseManager::Init() 
 
   Preferences::RegisterCallbackAndCall(MaxSerializedMsgSizePrefChangeCallback,
                                        kPrefMaxSerilizedMsgSize);
 
   Preferences::RegisterCallbackAndCall(AtomicBoolPrefChangedCallback,
                                        kPreprocessingPref,
                                        &gPreprocessingEnabled);
 
+  Preferences::RegisterCallbackAndCall(MaxPreloadExtraRecordsPrefChangeCallback,
+                                       kPrefMaxPreloadExtraRecords);
+
   nsAutoCString acceptLang;
   Preferences::GetLocalizedCString("intl.accept_languages", acceptLang);
 
   // Split values on commas.
   nsCCharSeparatedTokenizer langTokenizer(acceptLang, ',');
   while (langTokenizer.hasMoreTokens()) {
     nsAutoCString lang(langTokenizer.nextToken());
     icu::Locale locale = icu::Locale::createCanonical(lang.get());
@@ -628,16 +651,25 @@ uint32_t IndexedDatabaseManager::MaxSeri
 bool IndexedDatabaseManager::PreprocessingEnabled() {
   MOZ_ASSERT(gDBManager,
              "PreprocessingEnabled() called before indexedDB has been "
              "initialized!");
 
   return gPreprocessingEnabled;
 }
 
+// static
+int32_t IndexedDatabaseManager::MaxPreloadExtraRecords() {
+  MOZ_ASSERT(gDBManager,
+             "MaxPreloadExtraRecords() called before indexedDB has been "
+             "initialized!");
+
+  return gMaxPreloadExtraRecords;
+}
+
 void IndexedDatabaseManager::ClearBackgroundActor() {
   MOZ_ASSERT(NS_IsMainThread());
 
   mBackgroundActor = nullptr;
 }
 
 already_AddRefed<FileManager> IndexedDatabaseManager::GetFileManager(
     PersistenceType aPersistenceType, const nsACString& aOrigin,
--- a/dom/indexedDB/IndexedDatabaseManager.h
+++ b/dom/indexedDB/IndexedDatabaseManager.h
@@ -92,16 +92,20 @@ class IndexedDatabaseManager final {
   static bool IsFileHandleEnabled();
 
   static uint32_t DataThreshold();
 
   static uint32_t MaxSerializedMsgSize();
 
   static bool PreprocessingEnabled();
 
+  // The maximum number of extra entries to preload in an Cursor::OpenOp or
+  // Cursor::ContinueOp.
+  static int32_t MaxPreloadExtraRecords();
+
   void ClearBackgroundActor();
 
   already_AddRefed<FileManager> GetFileManager(PersistenceType aPersistenceType,
                                                const nsACString& aOrigin,
                                                const nsAString& aDatabaseName);
 
   void AddFileManager(FileManager* aFileManager);