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

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor_tables.cc

Issue 2385173002: predictors: Take the priority into account for scoring resources. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 | chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/predictors/resource_prefetch_predictor_tables.cc
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_tables.cc b/chrome/browser/predictors/resource_prefetch_predictor_tables.cc
index a300d5b0f2921d6dd316954579df3e6fdf583691..34d3ccf43f61f7f24f0bd9559bb4694801d4f470 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor_tables.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor_tables.cc
@@ -134,6 +134,7 @@ void ResourcePrefetchPredictorTables::SortResources(
std::vector<ResourceData>* resources) {
std::sort(resources->begin(), resources->end(),
[](const ResourceData& x, const ResourceData& y) {
+ // Decreasing score ordering.
return ComputeResourceScore(x) > ComputeResourceScore(y);
});
}
@@ -143,6 +144,7 @@ void ResourcePrefetchPredictorTables::SortRedirects(
std::vector<RedirectStat>* redirects) {
std::sort(redirects->begin(), redirects->end(),
[](const RedirectStat& x, const RedirectStat& y) {
+ // Decreasing score ordering.
return ComputeRedirectScore(x) > ComputeRedirectScore(y);
});
}
@@ -478,21 +480,46 @@ bool ResourcePrefetchPredictorTables::StringsAreSmallerThanDBLimit(
// static
float ResourcePrefetchPredictorTables::ComputeResourceScore(
const ResourceData& data) {
- // The score is calculated so that when the rows are sorted, stylesheets,
- // scripts and fonts appear first, sorted by position(ascending) and then the
- // rest of the resources sorted by position (ascending).
- static const int kMaxResourcesPerType = 100;
+ // The ranking is done by considering, in this order:
+ // 1. Resource Priority
+ // 2. Request resource type
+ // 3. Finally, the average position, giving a higher priotity to earlier
+ // resources.
+
+ int priority_multiplier;
+ switch (data.priority()) {
+ case ResourceData::REQUEST_PRIORITY_HIGHEST:
+ priority_multiplier = 3;
+ break;
+ case ResourceData::REQUEST_PRIORITY_MEDIUM:
+ priority_multiplier = 2;
+ break;
+ case ResourceData::REQUEST_PRIORITY_LOW:
+ case ResourceData::REQUEST_PRIORITY_LOWEST:
+ case ResourceData::REQUEST_PRIORITY_IDLE:
+ default:
+ priority_multiplier = 1;
+ break;
+ }
+
+ int type_multiplier;
switch (data.resource_type()) {
case ResourceData::RESOURCE_TYPE_STYLESHEET:
case ResourceData::RESOURCE_TYPE_SCRIPT:
+ type_multiplier = 3;
+ break;
case ResourceData::RESOURCE_TYPE_FONT_RESOURCE:
- return (2 * kMaxResourcesPerType) - data.average_position();
-
+ type_multiplier = 2;
+ break;
case ResourceData::RESOURCE_TYPE_IMAGE:
default:
- return kMaxResourcesPerType - data.average_position();
+ type_multiplier = 1;
}
- // TODO(lizeb): Take priority into account.
+
+ constexpr int kMaxResourcesPerType = 100;
+ return kMaxResourcesPerType *
+ (priority_multiplier * 100 + type_multiplier * 10) -
+ data.average_position();
}
// static
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetch_predictor_tables_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698