Bug 1313021 - Use a MEMORY SQLITE_TEMP_STORE on Android and 64bit builds. r=asuth
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 03 Nov 2016 22:11:59 +0100
changeset 347896 60046427323744b6384ef3ee14ec82feeb33d932
parent 347895 f943477f8ad2fa9536d6077af9cc608fe391aa66
child 347897 572249b2ffb6ccd84e7fb5ffdf529aceb557ce51
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1313021
milestone52.0a1
Bug 1313021 - Use a MEMORY SQLITE_TEMP_STORE on Android and 64bit builds. r=asuth MozReview-Commit-ID: IeXOY3tTStq
db/sqlite3/src/moz.build
storage/moz.build
storage/mozStorageConnection.cpp
--- a/db/sqlite3/src/moz.build
+++ b/db/sqlite3/src/moz.build
@@ -80,14 +80,25 @@ if CONFIG['OS_ARCH'] == 'WINNT' and CONF
     DEFINES['HAVE_MALLOC_USABLE_SIZE'] = True
     DEFINES['SQLITE_WITHOUT_MSIZE'] = True
 
 # Omit unused functions to save some library footprint.
 DEFINES['SQLITE_OMIT_DEPRECATED'] = True
 DEFINES['SQLITE_OMIT_BUILTIN_TEST'] = True
 DEFINES['SQLITE_OMIT_DECLTYPE'] = True
 
+# Try to use a MEMORY temp store when possible. That allows for better
+# performance and doesn't suffer from a full separate tmp partition.
+# Exclude 32bit platforms due to address space fragmentation issues.
+# System Sqlite is managed through a PRAGMA instead.
+if CONFIG['OS_TARGET'] == 'Android':
+    # On Android there's no tmp partition, so always use a MEMORY temp store.
+    DEFINES['SQLITE_TEMP_STORE'] = 3
+elif CONFIG['HAVE_64BIT_BUILD']:
+    # On 64bit platforms default to a MEMORY temp store for performance.
+    DEFINES['SQLITE_TEMP_STORE'] = 2
+
 # Suppress warnings in third-party code.
 if CONFIG['GNU_CC']:
     CFLAGS += [
         '-Wno-sign-compare',
         '-Wno-type-limits',
     ]
--- a/storage/moz.build
+++ b/storage/moz.build
@@ -102,14 +102,20 @@ if CONFIG['MOZ_MEMORY'] and (not CONFIG[
                              or CONFIG['MOZ_SYSTEM_JEMALLOC']):
     if CONFIG['OS_TARGET'] != 'Android':
         DEFINES['MOZ_STORAGE_MEMORY'] = True
 
 # This is the default value.  If we ever change it when compiling sqlite, we
 # will need to change it here as well.
 DEFINES['SQLITE_MAX_LIKE_PATTERN_LENGTH'] = 50000
 
+# See Sqlite moz.build for reasoning about TEMP_STORE.
+# For system sqlite we cannot use the compile time option, so we use a pragma.
+if CONFIG['MOZ_SYSTEM_SQLITE'] and (CONFIG['OS_TARGET'] == 'Android'
+                                    or CONFIG['HAVE_64BIT_BUILD']):
+    DEFINES['MOZ_MEMORY_TEMP_STORE_PRAGMA'] = True
+
 LOCAL_INCLUDES += [
     '/db/sqlite3/src',
     '/dom/base',
 ]
 
 CXXFLAGS += CONFIG['SQLITE_CFLAGS']
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -757,16 +757,20 @@ Connection::initializeInternal()
   cacheSizeQuery.AppendInt(-MAX_CACHE_SIZE_KIBIBYTES);
   int srv = executeSql(mDBConn, cacheSizeQuery.get());
   if (srv != SQLITE_OK) {
     ::sqlite3_close(mDBConn);
     mDBConn = nullptr;
     return convertResultCode(srv);
   }
 
+#if defined(MOZ_MEMORY_TEMP_STORE_PRAGMA)
+  (void)ExecuteSimpleSQL(NS_LITERAL_CSTRING("PRAGMA temp_store = 2;"));
+#endif
+
   // Register our built-in SQL functions.
   srv = registerFunctions(mDBConn);
   if (srv != SQLITE_OK) {
     ::sqlite3_close(mDBConn);
     mDBConn = nullptr;
     return convertResultCode(srv);
   }