Index: sql/connection.cc |
diff --git a/sql/connection.cc b/sql/connection.cc |
index 0511e11b5c5b22361bbdf24cc1230203749f272b..7500e6c9ebaeeeacc30a45ffcde7a441ad5351e6 100644 |
--- a/sql/connection.cc |
+++ b/sql/connection.cc |
@@ -14,6 +14,7 @@ |
#include "base/bind.h" |
#include "base/debug/alias.h" |
#include "base/debug/dump_without_crashing.h" |
+#include "base/feature_list.h" |
#include "base/files/file_path.h" |
#include "base/files/file_util.h" |
#include "base/format_macros.h" |
@@ -228,6 +229,15 @@ std::string AsUTF8ForSQL(const base::FilePath& path) { |
#endif |
} |
+// http://crbug.com/698010 |
+// |
+// The feature enables a SQLite patch which causes SQLite to leverage |
+// SQLITE_FCNTL_CHUNK_SIZE when making auto-vacuum decisions. This should lower |
+// write load (histogram Sqlite.Vfs_Write in vfs_wrapper.cc). Only Android |
+// enables auto-vacuum under Chromium. |
+const base::Feature kSqliteSmartAutoVacuumEnabled{ |
+ "SqliteSmartAutoVacuum", base::FEATURE_DISABLED_BY_DEFAULT}; |
+ |
} // namespace |
namespace sql { |
@@ -1851,6 +1861,19 @@ bool Connection::OpenInternal(const std::string& file_name, |
if (db_size > 128 * 1024) |
chunk_size = 32 * 1024; |
sqlite3_file_control(db_, NULL, SQLITE_FCNTL_CHUNK_SIZE, &chunk_size); |
+ if (base::FeatureList::IsEnabled(kSqliteSmartAutoVacuumEnabled)) { |
+ int page_size = 0; |
+ { |
+ sql::Statement stmt(GetUniqueStatement("PRAGMA page_size")); |
+ if (stmt.Step()) |
+ page_size = stmt.ColumnInt(0); |
+ if (!page_size) |
+ page_size = 1024; |
+ } |
+ std::string slack_sql = base::StringPrintf( |
+ "PRAGMA auto_vacuum_slack_pages = %d", chunk_size / page_size); |
+ ignore_result(Execute(slack_sql.c_str())); |
+ } |
} |
// Enable memory-mapped access. The explicit-disable case is because SQLite |