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

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

Issue 1246493002: Fix Resource Priorities and Scheduling (Blink Side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 5 years, 4 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 using blink::WebURLRequest; 56 using blink::WebURLRequest;
57 57
58 namespace blink { 58 namespace blink {
59 59
60 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request) 60 ResourceLoadPriority ResourceFetcher::loadPriority(Resource::Type type, const Fe tchRequest& request)
61 { 61 {
62 // TODO(yoav): Change it here so that priority can be changed even after it was resolved. 62 // TODO(yoav): Change it here so that priority can be changed even after it was resolved.
63 if (request.priority() != ResourceLoadPriorityUnresolved) 63 if (request.priority() != ResourceLoadPriorityUnresolved)
64 return request.priority(); 64 return request.priority();
65 65
66 // An image fetch is used to distinguish between "early" and "late" scripts in a document
67 if (type == Resource::Image)
68 m_imageFetched = true;
69
70 // Runtime experiment that change how we prioritize resources.
71 // The toggles do not depend on each other and can be flipped individually
72 // though the cumulative result will depend on the interaction between them.
73 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing
74 bool deferLateScripts = context().fetchDeferLateScripts();
75 bool increaseFontPriority = context().fetchIncreaseFontPriority();
76 bool increaseAsyncScriptPriority = context().fetchIncreaseAsyncScriptPriorit y();
77 // Increases the priorities for CSS, Scripts, Fonts and Images all by one le vel
78 // and parser-blocking scripts and visible images by 2.
79 // This is used in conjunction with logic on the Chrome side to raise the th reshold
80 // of "layout-blocking" resources and provide a boost to resources that are needed
81 // as soon as possible for something currently on the screen.
82 bool increasePriorities = context().fetchIncreasePriorities();
83
66 switch (type) { 84 switch (type) {
67 case Resource::MainResource: 85 case Resource::MainResource:
68 return context().isLowPriorityIframe() ? ResourceLoadPriorityVeryLow : R esourceLoadPriorityVeryHigh; 86 return context().isLowPriorityIframe() ? ResourceLoadPriorityVeryLow : R esourceLoadPriorityVeryHigh;
69 case Resource::CSSStyleSheet: 87 case Resource::CSSStyleSheet:
70 return ResourceLoadPriorityHigh; 88 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceLoadP riorityHigh;
71 case Resource::Raw: 89 case Resource::Raw:
72 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium; 90 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium;
73 case Resource::Script: 91 case Resource::Script:
74 // Async scripts do not block the parser so they get the lowest priority and can be 92 // Async/Defer scripts.
75 // loaded in parser order with images.
76 if (FetchRequest::LazyLoad == request.defer()) 93 if (FetchRequest::LazyLoad == request.defer())
77 return ResourceLoadPriorityLow; 94 return increaseAsyncScriptPriority ? ResourceLoadPriorityMedium : Re sourceLoadPriorityLow;
78 return ResourceLoadPriorityMedium; 95 // Reduce the priority of late-body scripts.
96 if (deferLateScripts && request.forPreload() && m_imageFetched)
97 return increasePriorities ? ResourceLoadPriorityMedium : ResourceLoa dPriorityLow;
98 // Parser-blocking scripts.
99 if (!request.forPreload())
100 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityMedium;
101 // Non-async/defer scripts discovered by the preload scanner (only early scripts if deferLateScripts is active).
102 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium;
79 case Resource::Font: 103 case Resource::Font:
104 if (increaseFontPriority)
105 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityHigh;
106 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium;
80 case Resource::ImportResource: 107 case Resource::ImportResource:
81 return ResourceLoadPriorityMedium; 108 return ResourceLoadPriorityMedium;
82 case Resource::Image: 109 case Resource::Image:
83 // Default images to VeryLow, and promote whatever is visible. This impr oves 110 // Default images to VeryLow, and promote when they become visible.
84 // speed-index by ~5% on average, ~14% at the 99th percentile. 111 return increasePriorities ? ResourceLoadPriorityLow : ResourceLoadPriori tyVeryLow;
85 return ResourceLoadPriorityVeryLow;
86 case Resource::Media: 112 case Resource::Media:
87 return ResourceLoadPriorityLow; 113 return ResourceLoadPriorityLow;
88 case Resource::XSLStyleSheet: 114 case Resource::XSLStyleSheet:
89 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); 115 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
90 return ResourceLoadPriorityHigh; 116 return ResourceLoadPriorityHigh;
91 case Resource::SVGDocument: 117 case Resource::SVGDocument:
92 return ResourceLoadPriorityLow; 118 return ResourceLoadPriorityLow;
93 case Resource::LinkPrefetch: 119 case Resource::LinkPrefetch:
94 case Resource::LinkPreload: 120 case Resource::LinkPreload:
95 return ResourceLoadPriorityVeryLow; 121 return ResourceLoadPriorityVeryLow;
96 case Resource::LinkSubresource: 122 case Resource::LinkSubresource:
97 return ResourceLoadPriorityLow; 123 return ResourceLoadPriorityLow;
98 case Resource::TextTrack: 124 case Resource::TextTrack:
99 return ResourceLoadPriorityLow; 125 return ResourceLoadPriorityLow;
100 } 126 }
127
101 ASSERT_NOT_REACHED(); 128 ASSERT_NOT_REACHED();
102 return ResourceLoadPriorityUnresolved; 129 return ResourceLoadPriorityUnresolved;
103 } 130 }
104 131
105 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) 132 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings)
106 { 133 {
107 info->setInitialRequest(resource->resourceRequest()); 134 info->setInitialRequest(resource->resourceRequest());
108 info->setFinalResponse(resource->response()); 135 info->setFinalResponse(resource->response());
109 if (clearLoadTimings) { 136 if (clearLoadTimings) {
110 info->clearLoadTimings(); 137 info->clearLoadTimings();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return WebURLRequest::RequestContextSubresource; 182 return WebURLRequest::RequestContextSubresource;
156 } 183 }
157 184
158 ResourceFetcher::ResourceFetcher(FetchContext* context) 185 ResourceFetcher::ResourceFetcher(FetchContext* context)
159 : m_context(context) 186 : m_context(context)
160 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired) 187 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired)
161 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired) 188 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired)
162 , m_autoLoadImages(true) 189 , m_autoLoadImages(true)
163 , m_imagesEnabled(true) 190 , m_imagesEnabled(true)
164 , m_allowStaleResources(false) 191 , m_allowStaleResources(false)
192 , m_imageFetched(false)
165 { 193 {
166 #if ENABLE(OILPAN) 194 #if ENABLE(OILPAN)
167 ThreadState::current()->registerPreFinalizer(this); 195 ThreadState::current()->registerPreFinalizer(this);
168 #endif 196 #endif
169 } 197 }
170 198
171 ResourceFetcher::~ResourceFetcher() 199 ResourceFetcher::~ResourceFetcher()
172 { 200 {
173 #if !ENABLE(OILPAN) 201 #if !ENABLE(OILPAN)
174 clearPreloads(); 202 clearPreloads();
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 visitor->trace(m_archiveResourceCollection); 1103 visitor->trace(m_archiveResourceCollection);
1076 visitor->trace(m_loaders); 1104 visitor->trace(m_loaders);
1077 visitor->trace(m_nonBlockingLoaders); 1105 visitor->trace(m_nonBlockingLoaders);
1078 #if ENABLE(OILPAN) 1106 #if ENABLE(OILPAN)
1079 visitor->trace(m_preloads); 1107 visitor->trace(m_preloads);
1080 visitor->trace(m_resourceTimingInfoMap); 1108 visitor->trace(m_resourceTimingInfoMap);
1081 #endif 1109 #endif
1082 } 1110 }
1083 1111
1084 } 1112 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceFetcher.h ('k') | Source/core/fetch/ResourceLoadPriorityOptimizer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698