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

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: Rebase Created 4 years, 5 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 // A deferred load of type Raw is a link rel=preload, which should be Lo w instead of VeryLow.
163 priority = type == Resource::Raw ? ResourceLoadPriorityLow : ResourceLoa dPriorityVeryLow;
169 } 164 }
170 165
171 return context().modifyPriorityForExperiments(priority); 166 // A manually set priority acts as a floor. This is used to ensure that sync hronous requests
167 // are always given the highest possible priority, as well as to ensure that there isn't priority
168 // churn if images move in and out of the viewport, or is displayed more tha n once, both in and out
169 // of the viewport.
170 return std::max(context().modifyPriorityForExperiments(priority), request.re sourceRequest().priority());
172 } 171 }
173 172
174 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) 173 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource)
175 { 174 {
176 info->setInitialRequest(resource->resourceRequest()); 175 info->setInitialRequest(resource->resourceRequest());
177 info->setFinalResponse(resource->response()); 176 info->setFinalResponse(resource->response());
178 } 177 }
179 178
180 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type) 179 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re source::Type type)
181 { 180 {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 417
419 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url())); 418 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace Event(request.url()));
420 419
421 if (!request.url().isValid()) 420 if (!request.url().isValid())
422 return nullptr; 421 return nullptr;
423 422
424 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction())) 423 if (!context().canRequest(factory.type(), request.resourceRequest(), MemoryC ache::removeFragmentIdentifierIfNeeded(request.url()), request.options(), reques t.forPreload(), request.getOriginRestriction()))
425 return nullptr; 424 return nullptr;
426 425
427 unsigned long identifier = createUniqueIdentifier(); 426 unsigned long identifier = createUniqueIdentifier();
428 request.setPriority(loadPriority(factory.type(), request, ResourcePriority:: NotVisible)); 427 request.mutableResourceRequest().setPriority(computeLoadPriority(factory.typ e(), request, ResourcePriority::NotVisible));
429 request.mutableResourceRequest().setPriority(request.priority());
430 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer()); 428 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), request.defer());
431 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type()); 429 context().willStartLoadingResource(identifier, request.mutableResourceReques t(), factory.type());
432 if (!request.url().isValid()) 430 if (!request.url().isValid())
433 return nullptr; 431 return nullptr;
434 432
435 if (!request.forPreload()) { 433 if (!request.forPreload()) {
436 V8DOMActivityLogger* activityLogger = nullptr; 434 V8DOMActivityLogger* activityLogger = nullptr;
437 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest) 435 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml httprequest)
438 activityLogger = V8DOMActivityLogger::currentActivityLogger(); 436 activityLogger = V8DOMActivityLogger::currentActivityLogger();
439 else 437 else
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 493
496 if (policy != Use) 494 if (policy != Use)
497 resource->setIdentifier(identifier); 495 resource->setIdentifier(identifier);
498 496
499 if (!request.forPreload() || policy != Use) { 497 if (!request.forPreload() || policy != Use) {
500 // When issuing another request for a resource that is already in-flight make 498 // When issuing another request for a resource that is already in-flight make
501 // sure to not demote the priority of the in-flight request. If the new request 499 // sure to not demote the priority of the in-flight request. If the new request
502 // isn't at the same priority as the in-flight request, only allow promo tions. 500 // isn't at the same priority as the in-flight request, only allow promo tions.
503 // This can happen when a visible image's priority is increased and then another 501 // This can happen when a visible image's priority is increased and then another
504 // reference to the image is parsed (which would be at a lower priority) . 502 // reference to the image is parsed (which would be at a lower priority) .
505 if (request.priority() > resource->resourceRequest().priority()) 503 if (request.resourceRequest().priority() > resource->resourceRequest().p riority())
506 resource->didChangePriority(request.priority(), 0); 504 resource->didChangePriority(request.resourceRequest().priority(), 0) ;
507 } 505 }
508 506
509 // If only the fragment identifiers differ, it is the same resource. 507 // If only the fragment identifiers differ, it is the same resource.
510 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); 508 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url()));
511 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData); 509 requestLoadStarted(identifier, resource, request, policy == Use ? ResourceLo adingFromCache : ResourceLoadingFromNetwork, isStaticData);
512 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource); 510 m_documentResources.set(MemoryCache::removeFragmentIdentifierIfNeeded(reques t.url()), resource);
513 511
514 // Returns with an existing resource if the resource does not need to start 512 // Returns with an existing resource if the resource does not need to start
515 // loading immediately. 513 // loading immediately.
516 // If revalidation policy was determined as |Revalidate|, the resource was 514 // If revalidation policy was determined as |Revalidate|, the resource was
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1079
1082 void ResourceFetcher::updateAllImageResourcePriorities() 1080 void ResourceFetcher::updateAllImageResourcePriorities()
1083 { 1081 {
1084 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities"); 1082 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource Priorities");
1085 for (const auto& documentResource : m_documentResources) { 1083 for (const auto& documentResource : m_documentResources) {
1086 Resource* resource = documentResource.value.get(); 1084 Resource* resource = documentResource.value.get();
1087 if (!resource || !resource->isImage() || !resource->isLoading()) 1085 if (!resource || !resource->isImage() || !resource->isLoading())
1088 continue; 1086 continue;
1089 1087
1090 ResourcePriority resourcePriority = resource->priorityFromObservers(); 1088 ResourcePriority resourcePriority = resource->priorityFromObservers();
1091 ResourceLoadPriority resourceLoadPriority = loadPriority(Resource::Image , FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resourcePrior ity.visibility); 1089 ResourceLoadPriority resourceLoadPriority = computeLoadPriority(Resource ::Image, FetchRequest(resource->resourceRequest(), FetchInitiatorInfo()), resour cePriority.visibility);
1092 if (resourceLoadPriority == resource->resourceRequest().priority()) 1090 if (resourceLoadPriority == resource->resourceRequest().priority())
1093 continue; 1091 continue;
1094 1092
1095 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue); 1093 resource->didChangePriority(resourceLoadPriority, resourcePriority.intra PriorityValue);
1096 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource->identifi er(), "ChangePriority", "priority", resourceLoadPriority); 1094 TRACE_EVENT_ASYNC_STEP_INTO1("blink.net", "Resource", resource->identifi er(), "ChangePriority", "priority", resourceLoadPriority);
1097 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue); 1095 context().dispatchDidChangeResourcePriority(resource->identifier(), reso urceLoadPriority, resourcePriority.intraPriorityValue);
1098 } 1096 }
1099 } 1097 }
1100 1098
1101 void ResourceFetcher::reloadLoFiImages() 1099 void ResourceFetcher::reloadLoFiImages()
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 visitor->trace(m_context); 1270 visitor->trace(m_context);
1273 visitor->trace(m_archive); 1271 visitor->trace(m_archive);
1274 visitor->trace(m_loaders); 1272 visitor->trace(m_loaders);
1275 visitor->trace(m_nonBlockingLoaders); 1273 visitor->trace(m_nonBlockingLoaders);
1276 visitor->trace(m_documentResources); 1274 visitor->trace(m_documentResources);
1277 visitor->trace(m_preloads); 1275 visitor->trace(m_preloads);
1278 visitor->trace(m_resourceTimingInfoMap); 1276 visitor->trace(m_resourceTimingInfoMap);
1279 } 1277 }
1280 1278
1281 } // namespace blink 1279 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.h ('k') | third_party/WebKit/Source/core/fetch/XSLStyleSheetResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698