Bug 1337672 - Part 1: Reduce the priority of prefetch network requests. r=mayhemer
authorChris Peterson <cpeterson@mozilla.com>
Wed, 18 Jan 2017 00:55:58 -0800
changeset 341809 c8da87f5401158c11a7d144d099532a303ea1652
parent 341808 d3f5466ed29bdda4230acb1a69bd5a38de3f02f0
child 341810 24793c847f3a15a8993865ebbf5375b16130d1ce
push id31343
push usercbook@mozilla.com
push dateFri, 10 Feb 2017 12:50:15 +0000
treeherdermozilla-central@b9c6246f13ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1337672
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337672 - Part 1: Reduce the priority of prefetch network requests. r=mayhemer Reduce the priority of <link rel="prefetch"> network requests from PRIORITY_NORMAL to PRIORITY_LOWEST, the same as favicons. These prefetch requests are already deferred until the browser is idle using nsIWebProgressListener, but we can also adjust their network request priority to reflect their low urgency. https://developer.mozilla.org/docs/Web/HTTP/Link_prefetching_FAQ#How_is_browser_idle_time_determined.3F MozReview-Commit-ID: 2PjGRGOgKUU
uriloader/prefetch/nsPrefetchService.cpp
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -9,16 +9,17 @@
 #include "nsICategoryManager.h"
 #include "nsIObserverService.h"
 #include "nsIWebProgress.h"
 #include "nsCURILoader.h"
 #include "nsICacheInfoChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsIURL.h"
 #include "nsISimpleEnumerator.h"
+#include "nsISupportsPriority.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsStreamUtils.h"
 #include "nsAutoPtr.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
@@ -151,16 +152,22 @@ nsPrefetchNode::OpenChannel()
     if (httpChannel) {
         httpChannel->SetReferrerWithPolicy(mReferrerURI, referrerPolicy);
         httpChannel->SetRequestHeader(
             NS_LITERAL_CSTRING("X-Moz"),
             NS_LITERAL_CSTRING("prefetch"),
             false);
     }
 
+    // Reduce the priority of prefetch network requests.
+    nsCOMPtr<nsISupportsPriority> priorityChannel = do_QueryInterface(mChannel);
+    if (priorityChannel) {
+      priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
+    }
+
     rv = mChannel->AsyncOpen2(this);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       // Drop the ref to the channel, because we don't want to end up with
       // cycles through it.
       mChannel = nullptr;
     }
     return rv;
 }