Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: sql/connection.cc

Issue 2728543008: [sql] Experiment to enable smart-vacuum on Android.
Patch Set: Just read page size. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sql/connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698