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

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

Issue 2385173002: predictors: Take the priority into account for scoring resources. (Closed)
Patch Set: 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
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..3ddfb172a023dd42f4610ebb2483f1f89fb16a18 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,45 @@ 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;
+ static constexpr int kMaxResourcesPerType = 100;
pasko 2016/10/03 16:48:20 is static constexpr better in some way than just c
Benoit L 2016/10/04 09:49:54 Done.
+ int priority_multiplier, type_multiplier;
+
+ // 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.
+ 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;
+ }
+
switch (data.resource_type()) {
pasko 2016/10/03 16:48:20 nit: Seems better to move declaration of kMaxResou
Benoit L 2016/10/04 09:49:54 Done.
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.
+
+ return kMaxResourcesPerType *
+ (priority_multiplier * 100 + type_multiplier * 10) -
+ data.average_position();
}
// static

Powered by Google App Engine
This is Rietveld 408576698