Commit e46005ce authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Limit the number of page hints that can be loaded to the memory

The threshold is controlled using field trial.
Also, add few more histograms to track any regressions.

Change-Id: I7901f70196dd23de5eec6fc9574602c71fbe0235
Bug: 882913
Reviewed-on: https://chromium-review.googlesource.com/1214748
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590550}
parent 5f97ef33
...@@ -176,6 +176,8 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromConfig( ...@@ -176,6 +176,8 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromConfig(
url_matcher::URLMatcherConditionSet::Vector all_conditions; url_matcher::URLMatcherConditionSet::Vector all_conditions;
std::set<std::string> seen_host_suffixes; std::set<std::string> seen_host_suffixes;
size_t total_resource_loading_hints_received = 0;
size_t total_page_patterns_with_resource_loading_hints_received = 0;
// Process hint configuration. // Process hint configuration.
for (const auto hint : config.hints()) { for (const auto hint : config.hints()) {
// We only support host suffixes at the moment. Skip anything else. // We only support host suffixes at the moment. Skip anything else.
...@@ -223,9 +225,37 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromConfig( ...@@ -223,9 +225,37 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromConfig(
if (ShouldProcessPageHints() && !hint.page_hints().empty()) { if (ShouldProcessPageHints() && !hint.page_hints().empty()) {
UMA_HISTOGRAM_COUNTS("ResourceLoadingHints.PageHints.ProcessedCount", UMA_HISTOGRAM_COUNTS("ResourceLoadingHints.PageHints.ProcessedCount",
hint.page_hints().size()); hint.page_hints().size());
hints->initial_hints_.push_back(hint);
for (const auto& page_hint : hint.page_hints()) {
for (const auto& optimization : page_hint.whitelisted_optimizations()) {
base::Optional<PreviewsType> previews_type =
ConvertProtoOptimizationTypeToPreviewsOptimizationType(
optimization.optimization_type());
if (!previews_type ||
previews_type != PreviewsType::RESOURCE_LOADING_HINTS) {
continue;
}
total_page_patterns_with_resource_loading_hints_received++;
total_resource_loading_hints_received +=
optimization.resource_loading_hints().size();
}
}
if (total_page_patterns_with_resource_loading_hints_received <=
previews::params::GetMaxPageHintsInMemoryThreshhold()) {
hints->initial_hints_.push_back(hint);
}
} }
} }
if (ShouldProcessPageHints()) {
UMA_HISTOGRAM_COUNTS_100000(
"ResourceLoadingHints.ResourceHints.TotalReceived",
total_resource_loading_hints_received);
UMA_HISTOGRAM_COUNTS_1000(
"ResourceLoadingHints.PageHints.TotalReceived",
total_page_patterns_with_resource_loading_hints_received);
}
hints->url_matcher_.AddConditionSets(all_conditions); hints->url_matcher_.AddConditionSets(all_conditions);
// Completed processing hints data without crashing so clear sentinel. // Completed processing hints data without crashing so clear sentinel.
......
...@@ -245,6 +245,12 @@ int ResourceLoadingHintsVersion() { ...@@ -245,6 +245,12 @@ int ResourceLoadingHintsVersion() {
kVersion, 0); kVersion, 0);
} }
size_t GetMaxPageHintsInMemoryThreshhold() {
return GetFieldTrialParamByFeatureAsInt(features::kResourceLoadingHints,
"max_page_hints_in_memory_threshold",
500);
}
bool IsOptimizationHintsEnabled() { bool IsOptimizationHintsEnabled() {
return base::FeatureList::IsEnabled(features::kOptimizationHints); return base::FeatureList::IsEnabled(features::kOptimizationHints);
} }
......
...@@ -128,6 +128,9 @@ int LitePageServerPreviewsVersion(); ...@@ -128,6 +128,9 @@ int LitePageServerPreviewsVersion();
int NoScriptPreviewsVersion(); int NoScriptPreviewsVersion();
int ResourceLoadingHintsVersion(); int ResourceLoadingHintsVersion();
// The maximum number of page hints that should be loaded to memory.
size_t GetMaxPageHintsInMemoryThreshhold();
// Whether server optimization hints are enabled. // Whether server optimization hints are enabled.
bool IsOptimizationHintsEnabled(); bool IsOptimizationHintsEnabled();
......
...@@ -84999,6 +84999,30 @@ uploading your change for review. ...@@ -84999,6 +84999,30 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="ResourceLoadingHints.PageHints.TotalReceived"
units="total page hints count">
<owner>tbansal@chromium.org</owner>
<summary>
The total count of page hints received by the browser from the component
updater. Only the page hints that have at least one resource loading hint
are counted. One sample is recorded every time optimization guide service
processes the optimization hints provided by the component updater. The
count of hints loaded to memory may be lower than this.
</summary>
</histogram>
<histogram name="ResourceLoadingHints.ResourceHints.TotalReceived"
units="total resource loading hints count">
<owner>tbansal@chromium.org</owner>
<summary>
The total count of resource loading hints across all page hints received by
the browser from the component updater. One sample is recorded every time
optimization guide service processes the optimization hints provided by the
component updater. The count of hints loaded to memory may be lower than
this.
</summary>
</histogram>
<histogram name="ResourceLoadingHints.ResourceLoadingBlocked" <histogram name="ResourceLoadingHints.ResourceLoadingBlocked"
units="loading blocked"> units="loading blocked">
<owner>tbansal@chromium.org</owner> <owner>tbansal@chromium.org</owner>
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