OLD | NEW |
---|---|
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 Loading... | |
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 // Background doc: https://docs.google.com/document/d/1bCDuq9H1ih9iNjgzyAL0g pwNFiEP4TZS-YLRp_RuMlc/edit?usp=sharing | |
72 bool deferLateScripts = context().fetchDeferLateScripts(); | |
73 bool increaseFontPriority = context().fetchIncreaseFontPriority(); | |
74 bool increaseAsyncScriptPriority = context().fetchIncreaseAsyncScriptPriorit y(); | |
75 bool increasePriorities = context().fetchIncreasePriorities(); | |
Bryan McQuade
2015/08/07 17:30:40
this is the only one that could probably use a com
Pat Meenan
2015/08/07 21:21:14
Added some documentation explaining it. All of th
| |
76 | |
66 switch (type) { | 77 switch (type) { |
67 case Resource::MainResource: | 78 case Resource::MainResource: |
68 return context().isLowPriorityIframe() ? ResourceLoadPriorityVeryLow : R esourceLoadPriorityVeryHigh; | 79 return context().isLowPriorityIframe() ? ResourceLoadPriorityVeryLow : R esourceLoadPriorityVeryHigh; |
69 case Resource::CSSStyleSheet: | 80 case Resource::CSSStyleSheet: |
70 return ResourceLoadPriorityHigh; | 81 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceLoadP riorityHigh; |
Bryan McQuade
2015/08/07 17:30:40
just an idea - perhaps we could add a member metho
Pat Meenan
2015/08/07 21:21:14
It's a little more complicated because not all of
Bryan McQuade
2015/08/10 19:27:09
Ah, interesting, didn't realize not all boosts wer
| |
71 case Resource::Raw: | 82 case Resource::Raw: |
72 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium; | 83 return request.options().synchronousPolicy == RequestSynchronously ? Res ourceLoadPriorityVeryHigh : ResourceLoadPriorityMedium; |
73 case Resource::Script: | 84 case Resource::Script: |
74 // Async scripts do not block the parser so they get the lowest priority and can be | 85 // Async/Defer scripts. |
75 // loaded in parser order with images. | |
76 if (FetchRequest::LazyLoad == request.defer()) | 86 if (FetchRequest::LazyLoad == request.defer()) |
77 return ResourceLoadPriorityLow; | 87 return increaseAsyncScriptPriority ? ResourceLoadPriorityMedium : Re sourceLoadPriorityLow; |
78 return ResourceLoadPriorityMedium; | 88 // Reduce the priority of late-body scripts. |
89 if (deferLateScripts && request.forPreload() && m_imageFetched) | |
90 return increasePriorities ? ResourceLoadPriorityMedium : ResourceLoa dPriorityLow; | |
91 // Parser-blocking scripts. | |
92 if (increasePriorities && !request.forPreload()) | |
93 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityMedium; | |
94 // Early scripts discovered by the preload scanner. | |
95 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium; | |
79 case Resource::Font: | 96 case Resource::Font: |
97 if (increaseFontPriority) | |
98 return increasePriorities ? ResourceLoadPriorityVeryHigh : ResourceL oadPriorityHigh; | |
99 return increasePriorities ? ResourceLoadPriorityHigh : ResourceLoadPrior ityMedium; | |
80 case Resource::ImportResource: | 100 case Resource::ImportResource: |
81 return ResourceLoadPriorityMedium; | 101 return ResourceLoadPriorityMedium; |
82 case Resource::Image: | 102 case Resource::Image: |
83 // Default images to VeryLow, and promote whatever is visible. This impr oves | 103 // Default images to VeryLow, and promote when they become visible. |
84 // speed-index by ~5% on average, ~14% at the 99th percentile. | 104 return increasePriorities ? ResourceLoadPriorityLow : ResourceLoadPriori tyVeryLow; |
85 return ResourceLoadPriorityVeryLow; | |
86 case Resource::Media: | 105 case Resource::Media: |
87 return ResourceLoadPriorityLow; | 106 return ResourceLoadPriorityLow; |
88 case Resource::XSLStyleSheet: | 107 case Resource::XSLStyleSheet: |
89 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | 108 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); |
90 return ResourceLoadPriorityHigh; | 109 return ResourceLoadPriorityHigh; |
91 case Resource::SVGDocument: | 110 case Resource::SVGDocument: |
92 return ResourceLoadPriorityLow; | 111 return ResourceLoadPriorityLow; |
93 case Resource::LinkPrefetch: | 112 case Resource::LinkPrefetch: |
94 case Resource::LinkPreload: | 113 case Resource::LinkPreload: |
95 return ResourceLoadPriorityVeryLow; | 114 return ResourceLoadPriorityVeryLow; |
96 case Resource::LinkSubresource: | 115 case Resource::LinkSubresource: |
97 return ResourceLoadPriorityLow; | 116 return ResourceLoadPriorityLow; |
98 case Resource::TextTrack: | 117 case Resource::TextTrack: |
99 return ResourceLoadPriorityLow; | 118 return ResourceLoadPriorityLow; |
100 } | 119 } |
120 | |
101 ASSERT_NOT_REACHED(); | 121 ASSERT_NOT_REACHED(); |
102 return ResourceLoadPriorityUnresolved; | 122 return ResourceLoadPriorityUnresolved; |
103 } | 123 } |
104 | 124 |
105 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) | 125 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource, bool clearLoadTimings) |
106 { | 126 { |
107 info->setInitialRequest(resource->resourceRequest()); | 127 info->setInitialRequest(resource->resourceRequest()); |
108 info->setFinalResponse(resource->response()); | 128 info->setFinalResponse(resource->response()); |
109 if (clearLoadTimings) { | 129 if (clearLoadTimings) { |
110 info->clearLoadTimings(); | 130 info->clearLoadTimings(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 return WebURLRequest::RequestContextSubresource; | 175 return WebURLRequest::RequestContextSubresource; |
156 } | 176 } |
157 | 177 |
158 ResourceFetcher::ResourceFetcher(FetchContext* context) | 178 ResourceFetcher::ResourceFetcher(FetchContext* context) |
159 : m_context(context) | 179 : m_context(context) |
160 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired) | 180 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl ectDocumentResourcesTimerFired) |
161 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired) | 181 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi merFired) |
162 , m_autoLoadImages(true) | 182 , m_autoLoadImages(true) |
163 , m_imagesEnabled(true) | 183 , m_imagesEnabled(true) |
164 , m_allowStaleResources(false) | 184 , m_allowStaleResources(false) |
185 , m_imageFetched(false) | |
165 { | 186 { |
166 } | 187 } |
167 | 188 |
168 ResourceFetcher::~ResourceFetcher() | 189 ResourceFetcher::~ResourceFetcher() |
169 { | 190 { |
170 clearPreloads(); | 191 clearPreloads(); |
171 } | 192 } |
172 | 193 |
173 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const | 194 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const |
174 { | 195 { |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 | 1087 |
1067 DEFINE_TRACE(ResourceFetcher) | 1088 DEFINE_TRACE(ResourceFetcher) |
1068 { | 1089 { |
1069 visitor->trace(m_context); | 1090 visitor->trace(m_context); |
1070 visitor->trace(m_archiveResourceCollection); | 1091 visitor->trace(m_archiveResourceCollection); |
1071 visitor->trace(m_loaders); | 1092 visitor->trace(m_loaders); |
1072 visitor->trace(m_nonBlockingLoaders); | 1093 visitor->trace(m_nonBlockingLoaders); |
1073 } | 1094 } |
1074 | 1095 |
1075 } | 1096 } |
OLD | NEW |