Title: [282094] branches/safari-612.1.29.41-branch/Source/WebKit
Revision
282094
Author
repst...@apple.com
Date
2021-09-07 10:54:05 -0700 (Tue, 07 Sep 2021)

Log Message

Cherry-pick r282003. rdar://problem/82828665

    Buffer large media XHRs in the NetworkProcess to reduce IPC overhead
    https://bugs.webkit.org/show_bug.cgi?id=229813
    <rdar://82406803>

    Reviewed by Alex Christensen.

    When playing back media through MSE, a significant amount of CPU time is spent sending
    small chunks of loaded media across the XPC boundary, on the order of 16kb at a time out
    of a 1-3MB resource. This large number of small XPC messages, each with a fixed cost, causes
    a relatively large CPU overhead. Media loaded directly through a HTMLMediaElement already
    is coalesced in the NetworkProcess on a 50ms timer.

    Buffer all loads of large media resources, performed over fetch() or XHR, when those resources
    have an expected length of more than 1MB, by coalescing them on the same 50ms timer as we use
    for HTMLMediaElement-generated loads.

    * NetworkProcess/NetworkResourceLoadParameters.h:
    * NetworkProcess/NetworkResourceLoader.cpp:
    (WebKit::NetworkResourceLoader::didReceiveResponse):
    * NetworkProcess/NetworkResourceLoader.h:
    * WebProcess/Network/WebLoaderStrategy.cpp:
    (WebKit::maximumBufferingTime):
    * WebProcess/Network/WebLoaderStrategy.h:

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

Modified Paths

Diff

Modified: branches/safari-612.1.29.41-branch/Source/WebKit/ChangeLog (282093 => 282094)


--- branches/safari-612.1.29.41-branch/Source/WebKit/ChangeLog	2021-09-07 16:48:34 UTC (rev 282093)
+++ branches/safari-612.1.29.41-branch/Source/WebKit/ChangeLog	2021-09-07 17:54:05 UTC (rev 282094)
@@ -1,3 +1,59 @@
+2021-09-07  Russell Epstein  <repst...@apple.com>
+
+        Cherry-pick r282003. rdar://problem/82828665
+
+    Buffer large media XHRs in the NetworkProcess to reduce IPC overhead
+    https://bugs.webkit.org/show_bug.cgi?id=229813
+    <rdar://82406803>
+    
+    Reviewed by Alex Christensen.
+    
+    When playing back media through MSE, a significant amount of CPU time is spent sending
+    small chunks of loaded media across the XPC boundary, on the order of 16kb at a time out
+    of a 1-3MB resource. This large number of small XPC messages, each with a fixed cost, causes
+    a relatively large CPU overhead. Media loaded directly through a HTMLMediaElement already
+    is coalesced in the NetworkProcess on a 50ms timer.
+    
+    Buffer all loads of large media resources, performed over fetch() or XHR, when those resources
+    have an expected length of more than 1MB, by coalescing them on the same 50ms timer as we use
+    for HTMLMediaElement-generated loads.
+    
+    * NetworkProcess/NetworkResourceLoadParameters.h:
+    * NetworkProcess/NetworkResourceLoader.cpp:
+    (WebKit::NetworkResourceLoader::didReceiveResponse):
+    * NetworkProcess/NetworkResourceLoader.h:
+    * WebProcess/Network/WebLoaderStrategy.cpp:
+    (WebKit::maximumBufferingTime):
+    * WebProcess/Network/WebLoaderStrategy.h:
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282003 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-03  Jer Noble  <jer.no...@apple.com>
+
+            Buffer large media XHRs in the NetworkProcess to reduce IPC overhead
+            https://bugs.webkit.org/show_bug.cgi?id=229813
+            <rdar://82406803>
+
+            Reviewed by Alex Christensen.
+
+            When playing back media through MSE, a significant amount of CPU time is spent sending
+            small chunks of loaded media across the XPC boundary, on the order of 16kb at a time out
+            of a 1-3MB resource. This large number of small XPC messages, each with a fixed cost, causes
+            a relatively large CPU overhead. Media loaded directly through a HTMLMediaElement already
+            is coalesced in the NetworkProcess on a 50ms timer.
+
+            Buffer all loads of large media resources, performed over fetch() or XHR, when those resources
+            have an expected length of more than 1MB, by coalescing them on the same 50ms timer as we use
+            for HTMLMediaElement-generated loads.
+
+            * NetworkProcess/NetworkResourceLoadParameters.h:
+            * NetworkProcess/NetworkResourceLoader.cpp:
+            (WebKit::NetworkResourceLoader::didReceiveResponse):
+            * NetworkProcess/NetworkResourceLoader.h:
+            * WebProcess/Network/WebLoaderStrategy.cpp:
+            (WebKit::maximumBufferingTime):
+            * WebProcess/Network/WebLoaderStrategy.h:
+
 2021-08-19  Kate Cheney  <katherine_che...@apple.com>
 
         Unable to load downloaded HTML files in Safari

Modified: branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h (282093 => 282094)


--- branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h	2021-09-07 16:48:34 UTC (rev 282093)
+++ branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h	2021-09-07 17:54:05 UTC (rev 282094)
@@ -54,7 +54,7 @@
     ResourceLoadIdentifier identifier { 0 };
     Vector<RefPtr<SandboxExtension>> requestBodySandboxExtensions; // Created automatically for the sender.
     RefPtr<SandboxExtension> resourceSandboxExtension; // Created automatically for the sender.
-    Seconds maximumBufferingTime;
+    mutable Seconds maximumBufferingTime;
     WebCore::FetchOptions options;
     std::optional<WebCore::ContentSecurityPolicyResponseHeaders> cspResponseHeaders;
     WebCore::CrossOriginEmbedderPolicy parentCrossOriginEmbedderPolicy;

Modified: branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (282093 => 282094)


--- branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2021-09-07 16:48:34 UTC (rev 282093)
+++ branches/safari-612.1.29.41-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2021-09-07 17:54:05 UTC (rev 282094)
@@ -43,6 +43,7 @@
 #include "SharedBufferDataReference.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebErrors.h"
+#include "WebLoaderStrategy.h"
 #include "WebPageMessages.h"
 #include "WebResourceLoaderMessages.h"
 #include "WebSWServerConnection.h"
@@ -633,6 +634,27 @@
         m_connection->addNetworkLoadInformation(identifier(), WTFMove(information));
     }
 
+    auto resourceLoadInfo = this->resourceLoadInfo();
+
+    auto isFetchOrXHR = [] (const ResourceLoadInfo& info) {
+        return info.type == ResourceLoadInfo::Type::Fetch
+            || info.type == ResourceLoadInfo::Type::XMLHTTPRequest;
+    };
+
+    auto isMediaMIMEType = [] (const String& mimeType) {
+        return mimeType.startsWithIgnoringASCIICase("audio/")
+            || mimeType.startsWithIgnoringASCIICase("video/")
+            || equalLettersIgnoringASCIICase(mimeType, "application/octet-stream");
+    };
+
+    if (!m_bufferedData
+        && m_response.expectedContentLength() > static_cast<long long>(1 * MB)
+        && isFetchOrXHR(resourceLoadInfo)
+        && isMediaMIMEType(m_response.mimeType())) {
+        m_bufferedData = SharedBuffer::create();
+        m_parameters.maximumBufferingTime = WebLoaderStrategy::mediaMaximumBufferingTime;
+    }
+
     // For multipart/x-mixed-replace didReceiveResponseAsync gets called multiple times and buffering would require special handling.
     if (!isSynchronous() && m_response.isMultipart())
         m_bufferedData = nullptr;
@@ -707,7 +729,7 @@
     send(Messages::WebResourceLoader::DidReceiveResponse { response, willWaitForContinueDidReceiveResponse });
 
     if (m_parameters.pageHasResourceLoadClient)
-        m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidReceiveResponse(m_parameters.webPageProxyID, resourceLoadInfo(), response), 0);
+        m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidReceiveResponse(m_parameters.webPageProxyID, resourceLoadInfo, response), 0);
 
     if (willWaitForContinueDidReceiveResponse) {
         m_responseCompletionHandler = WTFMove(completionHandler);

Modified: branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (282093 => 282094)


--- branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2021-09-07 16:48:34 UTC (rev 282093)
+++ branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2021-09-07 17:54:05 UTC (rev 282094)
@@ -151,7 +151,7 @@
     case CachedResource::Type::ImageResource:
         return 500_ms;
     case CachedResource::Type::MediaResource:
-        return 50_ms;
+        return WebLoaderStrategy::mediaMaximumBufferingTime;
     case CachedResource::Type::MainResource:
     case CachedResource::Type::Icon:
     case CachedResource::Type::RawResource:

Modified: branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h (282093 => 282094)


--- branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h	2021-09-07 16:48:34 UTC (rev 282093)
+++ branches/safari-612.1.29.41-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h	2021-09-07 17:54:05 UTC (rev 282094)
@@ -91,6 +91,8 @@
 
     static uint64_t generateLoadIdentifier();
 
+    static constexpr Seconds mediaMaximumBufferingTime { 50_ms };
+
 private:
     void scheduleLoad(WebCore::ResourceLoader&, WebCore::CachedResource*, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
     void scheduleInternallyFailedLoad(WebCore::ResourceLoader&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to