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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp

Issue 2072613002: Make ResourceLoadPriority calculation simpler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make the comment look more like English Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Also async scripts (set explicitly in loadPriority) 127 // Also async scripts (set explicitly in loadPriority)
128 return ResourceLoadPriorityLow; 128 return ResourceLoadPriorityLow;
129 case Resource::LinkPrefetch: 129 case Resource::LinkPrefetch:
130 return ResourceLoadPriorityVeryLow; 130 return ResourceLoadPriorityVeryLow;
131 } 131 }
132 132
133 ASSERT_NOT_REACHED(); 133 ASSERT_NOT_REACHED();
134 return ResourceLoadPriorityUnresolved; 134 return ResourceLoadPriorityUnresolved;
135 } 135 }
136 136
137 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request, ResourcePriority::VisibilityStatus visibility) 137 ResourceLoadPriority ResourceFetcher::computeLoadPriority(Resource::Type type, c onst FetchRequest& request, ResourcePriority::VisibilityStatus visibility)
138 { 138 {
139 // TODO(yoav): Change it here so that priority can be changed even after it was resolved.
140 if (request.priority() != ResourceLoadPriorityUnresolved)
141 return request.priority();
142
143 // Synchronous requests should always be max priority, lest they hang the re nderer.
144 if (request.options().synchronousPolicy == RequestSynchronously)
145 return ResourceLoadPriorityHighest;
146
147 ResourceLoadPriority priority = typeToPriority(type); 139 ResourceLoadPriority priority = typeToPriority(type);
148 140
149 // Visible resources (images in practice) get a boost to High priority. 141 // Visible resources (images in practice) get a boost to High priority.
150 if (visibility == ResourcePriority::Visible) 142 if (visibility == ResourcePriority::Visible)
151 priority = ResourceLoadPriorityHigh; 143 priority = ResourceLoadPriorityHigh;
152 144
153 // Resources before the first image are considered "early" in the document 145 // Resources before the first image are considered "early" in the document
154 // and resources after the first image are "late" in the document. Importan t to 146 // and resources after the first image are "late" in the document. Importan t to
155 // note that this is based on when the preload scanner discovers a resource 147 // note that this is based on when the preload scanner discovers a resource
156 // for the most part so the main parser may not have reached the image eleme nt yet. 148 // for the most part so the main parser may not have reached the image eleme nt yet.
157 if (type == Resource::Image) 149 if (type == Resource::Image)
158 m_imageFetched = true; 150 m_imageFetched = true;
159 151
160 // Special handling for scripts. 152 // Special handling for scripts.
161 // Default/Parser-Blocking/Preload early in document: High (set in typeToPri ority) 153 // Default/Parser-Blocking/Preload early in document: High (set in typeToPri ority)
162 // Async/Defer: Low Priority (applies to both preload and parser-inserted) 154 // Async/Defer: Low Priority (applies to both preload and parser-inserted)
163 // Preload late in document: Medium 155 // Preload late in document: Medium
164 if (type == Resource::Script) { 156 if (type == Resource::Script) {
165 if (FetchRequest::LazyLoad == request.defer()) 157 if (FetchRequest::LazyLoad == request.defer())
166 priority = ResourceLoadPriorityLow; 158 priority = ResourceLoadPriorityLow;
167 else if (request.forPreload() && m_imageFetched) 159 else if (request.forPreload() && m_imageFetched)
168 priority = ResourceLoadPriorityMedium; 160 priority = ResourceLoadPriorityMedium;
161 } else if (FetchRequest::LazyLoad == request.defer()) {
162 priority = ResourceLoadPriorityVeryLow;
Yoav Weiss 2016/06/25 08:37:59 If I understand it correctly, this would mean that
Pat Meenan 2016/06/27 14:56:55 Scripts go through the first clause and shouldn't
Nate Chapin 2016/06/27 19:46:16 Correct.
169 } 163 }
170 164
171 return context().modifyPriorityForExperiments(priority); 165 // A manually set priority acts as a floor. This is used to ensure that sync hronous requests
166 // are always given the highest possible priority, as well as to ensure that there isn't priority
167 // churn if images move in and out of the viewport.
168 return std::max(context().modifyPriorityForExperiments(priority), request.re sourceRequest().priority());
Yoav Weiss 2016/06/25 08:37:59 In the image case, the "priority churn" can also h
Pat Meenan 2016/06/27 14:56:55 We had logic previously to prevent exactly this ch
Nate Chapin 2016/06/27 19:46:16 I added a bit more detail to this comment, please
172 } 169 }
173 170
174 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) 171 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource)
175 { 172 {
176 info->setInitialRequest(resource->resourceRequest()); 173 info->setInitialRequest(resource->resourceRequest());
177 info->setFinalResponse(resource->response()); 174 info->setFinalResponse(resource->response());
178 } 175 }
179 176
180 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type) 177 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type)
181 { 178 {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 413
417 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url())); 414 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url()));
418 415
419 if (!request.url().isValid()) 416 if (!request.url().isValid())
420 return nullptr; 417 return nullptr;
421 418
422 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction())) 419 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction()))
423 return nullptr; 420 return nullptr;
424 421
425 unsigned long identifier = createUniqueIdentifier(); 422 unsigned long identifier = createUniqueIdentifier();
426 request.setPriority(loadPriority(factory.type(), request, ResourcePriority:: NotVisible)); 423 request.mutableResourceRequest().setPriority(computeLoadPriority(factory.typ e(), request, ResourcePriority::NotVisible));
427 request.mutableResourceRequest().setPriority(request.priority());
428 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer()); 424 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer());
429 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type()); 425 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type());
430 if (!request.url().isValid()) 426 if (!request.url().isValid())
431 return nullptr; 427 return nullptr;
432 428
433 if (!request.forPreload()) { 429 if (!request.forPreload()) {
434 V8DOMActivityLogger* activityLogger = nullptr; 430 V8DOMActivityLogger* activityLogger = nullptr;
435 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest) 431 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest)
436 activityLogger = V8DOMActivityLogger::currentActivityLogger(); 432 activityLogger = V8DOMActivityLogger::currentActivityLogger();
437 else 433 else
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 489
494 if (policy != Use) 490 if (policy != Use)
495 resource->setIdentifier(identifier); 491 resource->setIdentifier(identifier);
496 492
497 if (!request.forPreload() || policy != Use) { 493 if (!request.forPreload() || policy != Use) {
498 // When issuing another request for a resource that is already in-flight make 494 // When issuing another request for a resource that is already in-flight make
499 // sure to not demote the priority of the in-flight request. If the new request 495 // sure to not demote the priority of the in-flight request. If the new request
500 // isn't at the same priority as the in-flight request, only allow promo tions. 496 // isn't at the same priority as the in-flight request, only allow promo tions.
501 // This can happen when a visible image's priority is increased and then another 497 // This can happen when a visible image's priority is increased and then another
502 // reference to the image is parsed (which would be at a lower priority) . 498 // reference to the image is parsed (which would be at a lower priority) .
503 if (request.priority() > resource->resourceRequest().priority()) 499 if (request.resourceRequest().priority() > resource->resourceRequest().p riority())
504 resource->didChangePriority(request.priority(), 0); 500 resource->didChangePriority(request.resourceRequest().priority(), 0) ;
505 } 501 }
506 502
507 // If only the fragment identifiers differ, it is the same resource. 503 // If only the fragment identifiers differ, it is the same resource.
508 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); 504 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url()));
509 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData); 505 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData);
510 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource); 506 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource);
511 507
512 // Returns with an existing resource if the resource does not need to start 508 // Returns with an existing resource if the resource does not need to start
513 // loading immediately. 509 // loading immediately.
514 // If revalidation policy was determined as |Revalidate|, the resource was 510 // If revalidation policy was determined as |Revalidate|, the resource was
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 1066
1071 void ResourceFetcher::updateAllImageResourcePriorities() 1067 void ResourceFetcher::updateAllImageResourcePriorities()
1072 { 1068 {
1073 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities"); 1069 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities");
1074 for (const auto& documentResource : m_documentResources) { 1070 for (const auto& documentResource : m_documentResources) {
1075 Resource* resource = documentResource.value.get(); 1071 Resource* resource = documentResource.value.get();
1076 if (!resource || !resource->isImage() || !resource->isLoading()) 1072 if (!resource || !resource->isImage() || !resource->isLoading())
1077 continue; 1073 continue;
1078 1074
1079 ResourcePriority resourcePriority = resource->priorityFromObservers(); 1075 ResourcePriority resourcePriority = resource->priorityFromObservers();
1080 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image , FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior ity.visibility); 1076 ResourceLoadPriority resourceLoadPriority = computeLoadPriority(Resource ::Image, FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resour cePriority.visibility);
1081 if (resourceLoadPriority == resource->resourceRequest().priority()) 1077 if (resourceLoadPriority == resource->resourceRequest().priority())
1082 continue; 1078 continue;
1083 1079
1084 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue); 1080 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue);
1085 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangeP riority", "priority", resourceLoadPriority); 1081 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource, "ChangeP riority", "priority", resourceLoadPriority);
1086 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue); 1082 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue);
1087 } 1083 }
1088 } 1084 }
1089 1085
1090 void ResourceFetcher::reloadLoFiImages() 1086 void ResourceFetcher::reloadLoFiImages()
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 visitor->trace(m_context); 1257 visitor->trace(m_context);
1262 visitor->trace(m_archive); 1258 visitor->trace(m_archive);
1263 visitor->trace(m_loaders); 1259 visitor->trace(m_loaders);
1264 visitor->trace(m_nonBlockingLoaders); 1260 visitor->trace(m_nonBlockingLoaders);
1265 visitor->trace(m_documentResources); 1261 visitor->trace(m_documentResources);
1266 visitor->trace(m_preloads); 1262 visitor->trace(m_preloads);
1267 visitor->trace(m_resourceTimingInfoMap); 1263 visitor->trace(m_resourceTimingInfoMap);
1268 } 1264 }
1269 1265
1270 } // namespace blink 1266 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698