Commit 6b42b958 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] InMemoryURLIndex: Add flag to disable persisting index to disk

This CL adds a base::Feature flag that disables the HistoryQuickProvider
InMemoryURLIndex's cache file. Instead, the index will be rebuilt on
every startup from the History DB.

That's not as disastrous as it sounds. It takes ~2.5x as long compared
to the on-disk persisted cache, and doesn't block the UI. It's on the
History DB thread.

Details of experiment: go/chrome-omnibox-hqp-ablate-cache-file

Change-Id: Idddca4c5621010f3415e61d8731b3009892c281e
Bug: 750845, 1032679, 1141539
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441044
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821009}
parent 8a7ae891
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/strings/stringprintf.h"
......@@ -22,6 +23,7 @@
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/url_database.h"
#include "components/omnibox/browser/url_index_private_data.h"
#include "components/omnibox/common/omnibox_features.h"
using in_memory_url_index::InMemoryURLIndexCacheItem;
......@@ -240,6 +242,13 @@ void InMemoryURLIndex::PostRestoreFromCacheFileTask() {
DCHECK(thread_checker_.CalledOnValidThread());
TRACE_EVENT0("browser", "InMemoryURLIndex::PostRestoreFromCacheFileTask");
if (base::FeatureList::IsEnabled(
omnibox::kHistoryQuickProviderAblateInMemoryURLIndexCacheFile)) {
// To short circuit the cache, pretend we've failed to load it.
OnCacheLoadDone(nullptr);
return;
}
base::FilePath path;
if (!GetCacheFilePath(&path) || shutdown_) {
restored_ = true;
......@@ -292,11 +301,16 @@ void InMemoryURLIndex::Shutdown() {
if (!GetCacheFilePath(&path))
return;
private_data_tracker_.TryCancelAll();
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(base::IgnoreResult(
&URLIndexPrivateData::WritePrivateDataToCacheFileTask),
private_data_, path));
if (!base::FeatureList::IsEnabled(
omnibox::kHistoryQuickProviderAblateInMemoryURLIndexCacheFile)) {
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
base::IgnoreResult(
&URLIndexPrivateData::WritePrivateDataToCacheFileTask),
private_data_, path));
}
#ifndef LEAK_SANITIZER
// Intentionally create and then leak a scoped_refptr to private_data_. This
// permanently raises the reference count so that the URLIndexPrivateData
......@@ -349,6 +363,11 @@ void InMemoryURLIndex::RebuildFromHistory(
// Saving to Cache -------------------------------------------------------------
void InMemoryURLIndex::PostSaveToCacheFileTask() {
if (base::FeatureList::IsEnabled(
omnibox::kHistoryQuickProviderAblateInMemoryURLIndexCacheFile)) {
return;
}
base::FilePath path;
if (!GetCacheFilePath(&path))
return;
......
......@@ -262,6 +262,14 @@ const base::Feature kOnDeviceHeadProviderNonIncognito{
const base::Feature kOmniboxExperimentalSuggestScoring{
"OmniboxExperimentalSuggestScoring", base::FEATURE_DISABLED_BY_DEFAULT};
// If enabled, the HistoryQuickProvider's InMemoryURLIndex service never
// persists its index to a cache file on shutdown, and instead always rebuilds
// it from the HistoryService on startup. Persisting the index to disk causes
// over 10% of all shutdown hangs.
const base::Feature kHistoryQuickProviderAblateInMemoryURLIndexCacheFile{
"OmniboxHistoryQuickProviderAblateInMemoryURLIndexCacheFile",
base::FEATURE_DISABLED_BY_DEFAULT};
// If disabled, terms with no wordstart matches disqualify the suggestion unless
// they occur in the URL host. If enabled, terms with no wordstart matches are
// allowed but not scored. E.g., both inputs 'java script' and 'java cript' will
......
......@@ -72,8 +72,9 @@ extern const base::Feature kReactiveZeroSuggestionsOnNTPRealbox;
extern const base::Feature kOnDeviceHeadProviderIncognito;
extern const base::Feature kOnDeviceHeadProviderNonIncognito;
// Scoring - these affect how relevance scores are calculated for suggestions.
// Provider-specific - These features change the behavior of specific providers.
extern const base::Feature kOmniboxExperimentalSuggestScoring;
extern const base::Feature kHistoryQuickProviderAblateInMemoryURLIndexCacheFile;
extern const base::Feature kHistoryQuickProviderAllowButDoNotScoreMidwordTerms;
extern const base::Feature kHistoryQuickProviderAllowMidwordContinuations;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment