diff options
author | simonjam@chromium.org <simonjam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 04:58:21 +0000 |
---|---|---|
committer | simonjam@chromium.org <simonjam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 04:58:21 +0000 |
commit | 0cb0e55b2d197b85fbc6dc38884b72ca3d261141 (patch) | |
tree | e229aeb2d8296895f4ee7f3557c30c1b2c94b949 /content/browser/loader/resource_scheduler.h | |
parent | c82770859564df2097b1127b942eda5ca360145f (diff) | |
download | chromium_src-0cb0e55b2d197b85fbc6dc38884b72ca3d261141.zip chromium_src-0cb0e55b2d197b85fbc6dc38884b72ca3d261141.tar.gz chromium_src-0cb0e55b2d197b85fbc6dc38884b72ca3d261141.tar.bz2 |
Limit to only 10 image requests per page in ResourceScheduler.
The pending requests are now kept in a net::PriorityQueue. Priority changes
affect the order of the queue. After painting or network idle, we'll load up to
10 images simultaneously in PriorityQueue order.
This is a 2% improvement in Speed Index, 4% in first paint, and 5% in
DOMContentLoaded. There is a 0.5% regression in onload.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/12874003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/loader/resource_scheduler.h')
-rw-r--r-- | content/browser/loader/resource_scheduler.h | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/content/browser/loader/resource_scheduler.h b/content/browser/loader/resource_scheduler.h index fa53c5b..d971113 100644 --- a/content/browser/loader/resource_scheduler.h +++ b/content/browser/loader/resource_scheduler.h @@ -7,15 +7,14 @@ #include <map> #include <set> -#include <vector> #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" #include "content/common/content_export.h" -#include "content/public/browser/global_request_id.h" +#include "net/base/priority_queue.h" +#include "net/base/request_priority.h" namespace net { class URLRequest; @@ -32,6 +31,11 @@ class ResourceThrottle; // 2. Notifications for renderer events, such as new tabs, navigation and // painting. // +// These input come from different threads, so they may not be in sync. The UI +// thread is considered the authority on renderer lifetime, which means some +// IPCs may be meaningless if they arrive after the UI thread signals a renderer +// has been deleted. +// // The ResourceScheduler tracks many Clients, which should correlate with tabs. // A client is uniquely identified by its child_id and route_id. // @@ -56,12 +60,16 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { scoped_ptr<ResourceThrottle> ScheduleRequest( int child_id, int route_id, net::URLRequest* url_request); + // Signals from the UI thread, posted as tasks on the IO thread: + // Called when a renderer is created. void OnClientCreated(int child_id, int route_id); // Called when a renderer is destroyed. void OnClientDeleted(int child_id, int route_id); + // Signals from IPC messages directly from the renderers: + // Called when a client navigates to a new main document. void OnNavigate(int child_id, int route_id); @@ -70,32 +78,41 @@ class CONTENT_EXPORT ResourceScheduler : public base::NonThreadSafe { void OnWillInsertBody(int child_id, int route_id); private: + class RequestQueue; class ScheduledResourceRequest; - friend class ScheduledResourceRequest; struct Client; typedef int64 ClientId; typedef std::map<ClientId, Client*> ClientMap; - typedef std::vector<ScheduledResourceRequest*> RequestQueue; typedef std::set<ScheduledResourceRequest*> RequestSet; - struct Client { - Client(); - ~Client(); - - bool has_body; - RequestQueue pending_requests; - RequestSet in_flight_requests; - }; - // Called when a ScheduledResourceRequest is destroyed. void RemoveRequest(ScheduledResourceRequest* request); // Unthrottles the |request| and adds it to |client|. void StartRequest(ScheduledResourceRequest* request, Client* client); - // Calls StartRequest on all pending requests for |client|. - void LoadPendingRequests(Client* client); + // Update the queue position for |request|, possibly causing it to start + // loading. + // + // Queues are maintained for each priority level. When |request| is + // reprioritized, it will move to the end of the queue for that priority + // level. + void ReprioritizeRequest(ScheduledResourceRequest* request, + net::RequestPriority new_priority); + + // Attempts to load any pending requests in |client|, based on the + // results of ShouldStartRequest(). + void LoadAnyStartablePendingRequests(Client* client); + + // Returns the number of requests with priority < LOW that are currently in + // flight. + size_t GetNumDelayableRequestsInFlight(Client* client) const; + + // Returns true if the request should start. This is the core scheduling + // algorithm. + bool ShouldStartRequest(ScheduledResourceRequest* request, + Client* client) const; // Returns the client ID for the given |child_id| and |route_id| combo. ClientId MakeClientId(int child_id, int route_id); |