Bug 1313021 - Use a MEMORY SQLITE_TEMP_STORE on Android and 64bit builds. r=asuth
MozReview-Commit-ID: IeXOY3tTStq
--- 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);
}