VeryHigh priority loads are actually loading at VeryLow priority
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 22:41:08 +0000 (22:41 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 22:41:08 +0000 (22:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=203423
<rdar://problem/56621789>

Patch by Benjamin Nham <nham@apple.com> on 2019-11-13
Reviewed by Antti Koivisto.

There are two issues with the way we translate ResourceLoadPriority to
CFURLRequestPriority:

1. We call _CFNetworkHTTPConnectionCacheSetLimit and set 1 too few
priority levels. This means VeryHigh priority loads are actually out
of bounds, which causes CFNetwork to set the priority level back to 0
in HTTPConnectionCacheEntry::_prepareNewRequest. After this patch we'll
call _CFNetworkHTTPConnectionCacheSetLimit with the correct number of
levels.

2. _CFNetworkHTTPConnectionCacheSetLimit doesn't work for NSURLSession
right now (<rdar://problem/56621205>), so we have to map to the default
number of CFURLRequestPriority levels, which is 4. Right now we have 5
ResourceLoadPriority levels, so there will be some aliasing involved.
After this patch VeryLow gets a priority of -1 and Low gets a priority
of 0, but due to the aforementioned clamping behavior both VeryLow and
Low will effectively both have a CFURLRequestPriority of 0.

Source/WebCore:

* platform/network/cf/ResourceRequestCFNet.cpp:
(WebCore::initializeMaximumHTTPConnectionCountPerHost):
(WebCore::initializeHTTPConnectionSettingsOnStartup):
* platform/network/cf/ResourceRequestCFNet.h:
(WebCore::toResourceLoadPriority):
(WebCore::toPlatformRequestPriority):

Source/WebKit:

* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::initializeNetworkSettings):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@252431 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp
Source/WebCore/platform/network/cf/ResourceRequestCFNet.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm

index be0e497..0e27f67 100644 (file)
@@ -1,3 +1,36 @@
+2019-11-13  Benjamin Nham  <nham@apple.com>
+
+        VeryHigh priority loads are actually loading at VeryLow priority
+        https://bugs.webkit.org/show_bug.cgi?id=203423
+        <rdar://problem/56621789>
+
+        Reviewed by Antti Koivisto.
+
+        There are two issues with the way we translate ResourceLoadPriority to
+        CFURLRequestPriority:
+
+        1. We call _CFNetworkHTTPConnectionCacheSetLimit and set 1 too few
+        priority levels. This means VeryHigh priority loads are actually out
+        of bounds, which causes CFNetwork to set the priority level back to 0
+        in HTTPConnectionCacheEntry::_prepareNewRequest. After this patch we'll
+        call _CFNetworkHTTPConnectionCacheSetLimit with the correct number of
+        levels.
+
+        2. _CFNetworkHTTPConnectionCacheSetLimit doesn't work for NSURLSession
+        right now (<rdar://problem/56621205>), so we have to map to the default
+        number of CFURLRequestPriority levels, which is 4. Right now we have 5
+        ResourceLoadPriority levels, so there will be some aliasing involved.
+        After this patch VeryLow gets a priority of -1 and Low gets a priority
+        of 0, but due to the aforementioned clamping behavior both VeryLow and
+        Low will effectively both have a CFURLRequestPriority of 0.
+
+        * platform/network/cf/ResourceRequestCFNet.cpp:
+        (WebCore::initializeMaximumHTTPConnectionCountPerHost):
+        (WebCore::initializeHTTPConnectionSettingsOnStartup):
+        * platform/network/cf/ResourceRequestCFNet.h:
+        (WebCore::toResourceLoadPriority):
+        (WebCore::toPlatformRequestPriority):
+
 2019-11-13  Dean Jackson  <dino@apple.com>
 
         Fix some WebGPU demos
index b1b4bbf..3352945 100644 (file)
@@ -414,7 +414,7 @@ unsigned initializeMaximumHTTPConnectionCountPerHost()
     if (!ResourceRequest::resourcePrioritiesEnabled())
         return maximumHTTPConnectionCountPerHost;
 
-    _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, toPlatformRequestPriority(ResourceLoadPriority::Highest));
+    _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, resourceLoadPriorityCount);
 #if !PLATFORM(WIN)
     // FIXME: <rdar://problem/9375609> Implement minimum fast lane priority setting on Windows
     _CFNetworkHTTPConnectionCacheSetLimit(kHTTPMinimumFastLanePriority, toPlatformRequestPriority(ResourceLoadPriority::Medium));
@@ -433,7 +433,7 @@ void initializeHTTPConnectionSettingsOnStartup()
     static const unsigned preferredConnectionCount = 6;
     static const unsigned fastLaneConnectionCount = 1;
     _CFNetworkHTTPConnectionCacheSetLimit(kHTTPLoadWidth, preferredConnectionCount);
-    _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, toPlatformRequestPriority(ResourceLoadPriority::Highest));
+    _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, resourceLoadPriorityCount);
     _CFNetworkHTTPConnectionCacheSetLimit(kHTTPMinimumFastLanePriority, toPlatformRequestPriority(ResourceLoadPriority::Medium));
     _CFNetworkHTTPConnectionCacheSetLimit(kHTTPNumFastLanes, fastLaneConnectionCount);
 }
index 967d781..49d5d5e 100644 (file)
@@ -40,17 +40,17 @@ CFURLRequestRef cfURLRequest(const ResourceRequest&);
 
 inline ResourceLoadPriority toResourceLoadPriority(CFURLRequestPriority priority)
 {
+    // FIXME: switch VeryLow back to 0 priority when CFNetwork fixes <rdar://problem/56621205>
     switch (priority) {
     case -1:
-    case 0:
         return ResourceLoadPriority::VeryLow;
-    case 1:
+    case 0:
         return ResourceLoadPriority::Low;
-    case 2:
+    case 1:
         return ResourceLoadPriority::Medium;
-    case 3:
+    case 2:
         return ResourceLoadPriority::High;
-    case 4:
+    case 3:
         return ResourceLoadPriority::VeryHigh;
     default:
         ASSERT_NOT_REACHED();
@@ -60,17 +60,18 @@ inline ResourceLoadPriority toResourceLoadPriority(CFURLRequestPriority priority
 
 inline CFURLRequestPriority toPlatformRequestPriority(ResourceLoadPriority priority)
 {
+    // FIXME: switch VeryLow back to 0 priority when CFNetwork fixes <rdar://problem/56621205>
     switch (priority) {
     case ResourceLoadPriority::VeryLow:
-        return 0;
+        return -1;
     case ResourceLoadPriority::Low:
-        return 1;
+        return 0;
     case ResourceLoadPriority::Medium:
-        return 2;
+        return 1;
     case ResourceLoadPriority::High:
-        return 3;
+        return 2;
     case ResourceLoadPriority::VeryHigh:
-        return 4;
+        return 3;
     }
 
     ASSERT_NOT_REACHED();
index 7ccec80..3150d31 100644 (file)
@@ -1,3 +1,32 @@
+2019-11-13  Benjamin Nham  <nham@apple.com>
+
+        VeryHigh priority loads are actually loading at VeryLow priority
+        https://bugs.webkit.org/show_bug.cgi?id=203423
+        <rdar://problem/56621789>
+
+        Reviewed by Antti Koivisto.
+
+        There are two issues with the way we translate ResourceLoadPriority to
+        CFURLRequestPriority:
+
+        1. We call _CFNetworkHTTPConnectionCacheSetLimit and set 1 too few
+        priority levels. This means VeryHigh priority loads are actually out
+        of bounds, which causes CFNetwork to set the priority level back to 0
+        in HTTPConnectionCacheEntry::_prepareNewRequest. After this patch we'll
+        call _CFNetworkHTTPConnectionCacheSetLimit with the correct number of
+        levels.
+
+        2. _CFNetworkHTTPConnectionCacheSetLimit doesn't work for NSURLSession
+        right now (<rdar://problem/56621205>), so we have to map to the default
+        number of CFURLRequestPriority levels, which is 4. Right now we have 5
+        ResourceLoadPriority levels, so there will be some aliasing involved.
+        After this patch VeryLow gets a priority of -1 and Low gets a priority
+        of 0, but due to the aforementioned clamping behavior both VeryLow and
+        Low will effectively both have a CFURLRequestPriority of 0.
+
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::initializeNetworkSettings):
+
 2019-11-13  Youenn Fablet  <youenn@apple.com>
 
         Remove timer to stop service worker process
index 686e158..4af374b 100644 (file)
@@ -62,7 +62,7 @@ static void initializeNetworkSettings()
     if (WebCore::ResourceRequest::resourcePrioritiesEnabled()) {
         const unsigned fastLaneConnectionCount = 1;
 
-        _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, toPlatformRequestPriority(WebCore::ResourceLoadPriority::Highest));
+        _CFNetworkHTTPConnectionCacheSetLimit(kHTTPPriorityNumLevels, WebCore::resourceLoadPriorityCount);
         _CFNetworkHTTPConnectionCacheSetLimit(kHTTPMinimumFastLanePriority, toPlatformRequestPriority(WebCore::ResourceLoadPriority::Medium));
         _CFNetworkHTTPConnectionCacheSetLimit(kHTTPNumFastLanes, fastLaneConnectionCount);
     }