Title: [282979] branches/safari-612-branch/Source/WebKit
Revision
282979
Author
[email protected]
Date
2021-09-23 12:14:59 -0700 (Thu, 23 Sep 2021)

Log Message

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

    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-branch/Source/WebKit/ChangeLog (282978 => 282979)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-23 18:58:59 UTC (rev 282978)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-23 19:14:59 UTC (rev 282979)
@@ -1,3 +1,59 @@
+2021-09-23  Alan Coon  <[email protected]>
+
+        Cherry-pick r282003. rdar://problem/82734050
+
+    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  <[email protected]>
+
+            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-09-22  Alan Coon  <[email protected]>
 
         Cherry-pick r282789. rdar://problem/83429661

Modified: branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h (282978 => 282979)


--- branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h	2021-09-23 18:58:59 UTC (rev 282978)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h	2021-09-23 19:14:59 UTC (rev 282979)
@@ -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-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (282978 => 282979)


--- branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2021-09-23 18:58:59 UTC (rev 282978)
+++ branches/safari-612-branch/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2021-09-23 19:14:59 UTC (rev 282979)
@@ -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-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (282978 => 282979)


--- branches/safari-612-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2021-09-23 18:58:59 UTC (rev 282978)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2021-09-23 19:14:59 UTC (rev 282979)
@@ -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-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h (282978 => 282979)


--- branches/safari-612-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h	2021-09-23 18:58:59 UTC (rev 282978)
+++ branches/safari-612-branch/Source/WebKit/WebProcess/Network/WebLoaderStrategy.h	2021-09-23 19:14:59 UTC (rev 282979)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to