diff --git a/sql/database.cc b/sql/database.cc index 802923ce412d75..3ef9c18dc3838a 100644 --- a/sql/database.cc +++ b/sql/database.cc @@ -31,6 +31,7 @@ #include "sql/database_memory_dump_provider.h" #include "sql/initialization.h" #include "sql/meta_table.h" +#include "sql/sql_features.h" #include "sql/statement.h" #include "sql/vfs_wrapper.h" #include "third_party/sqlite/sqlite3.h" @@ -346,6 +347,9 @@ void Database::Preload() { base::Optional scoped_blocking_call; InitScopedBlockingCall(&scoped_blocking_call); + if (base::FeatureList::IsEnabled(features::kSqlSkipPreload)) + return; + if (!db_) { DCHECK(poisoned_) << "Cannot preload null db"; return; diff --git a/sql/sql_features.cc b/sql/sql_features.cc index 93d84e125533b2..833c43e00b0085 100644 --- a/sql/sql_features.cc +++ b/sql/sql_features.cc @@ -8,7 +8,17 @@ namespace sql { namespace features { -// Flags for SQLite configuration experiments will be defined here. +// Skip the logic for preloading databases. +// +// Enabling this feature turns sql::Database::Preload() into a noop. +// https://crbug.com/243949 suggests that sql::Database::Preload() was added +// without any proper benchmarking, and the logic is a pessimization for modern +// OS schedulers. +// +// TODO(pwnall): After the performance impact of the change is assessed, remove +// sql::Database::Preload() and this flag. +const base::Feature kSqlSkipPreload{"SqlSkipPreload", + base::FEATURE_DISABLED_BY_DEFAULT}; } // namespace features diff --git a/sql/sql_features.h b/sql/sql_features.h index 4acfc54fb32382..eee57706634ade 100644 --- a/sql/sql_features.h +++ b/sql/sql_features.h @@ -12,7 +12,7 @@ namespace sql { namespace features { -// Flags for SQLite configuration experiments will be declared here. +COMPONENT_EXPORT(SQL) extern const base::Feature kSqlSkipPreload; } // namespace features diff --git a/testing/variations/fieldtrial_testing_config.json b/testing/variations/fieldtrial_testing_config.json index d2a9d41fc8848b..dc3501070ff50c 100644 --- a/testing/variations/fieldtrial_testing_config.json +++ b/testing/variations/fieldtrial_testing_config.json @@ -4873,6 +4873,26 @@ ] } ], + "SqlSkipPreload": [ + { + "platforms": [ + "android", + "chromeos", + "linux", + "mac", + "ios", + "windows" + ], + "experiments": [ + { + "name": "Enabled", + "enable_features": [ + "SqlSkipPreload" + ] + } + ] + } + ], "StabilityDebugging": [ { "platforms": [