Index: sql/connection.cc |
diff --git a/sql/connection.cc b/sql/connection.cc |
index 0511e11b5c5b22361bbdf24cc1230203749f272b..a65cbb9fc15f881deb6b2cfcfa33accd6e2fb8a2 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,15 @@ 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)) { |
+ // TODO(shess): The default page size is now 4096. Before committing to |
+ // this long-term, fix that. Meanwhile, this should be fine, it might |
+ // leave a few databases using a bit more disk space than expected. |
+ const int page_size = page_size_ ? page_size_ : 1024; |
Maria
2017/03/28 22:14:59
The 1024 constant here for page_size, is this just
Scott Hess - ex-Googler
2017/03/29 03:28:46
Maybe I'll elaborate the comment. SQLite's defaul
Scott Hess - ex-Googler
2017/03/29 21:11:24
Bah, I just went with fetching the page-size from
|
+ 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 |