Title: [289295] branches/safari-613-branch/Source/WebCore
Revision
289295
Author
[email protected]
Date
2022-02-07 18:54:41 -0800 (Mon, 07 Feb 2022)

Log Message

Cherry-pick r288463. rdar://problem/87977499

    file.stream() is slow and CPU-bound
    https://bugs.webkit.org/show_bug.cgi?id=235448

    Reviewed by Alex Christensen.

    We introduce a ReadAsBinaryChunks mode to prevent storing the whole file in memory.
    Use this in Blob stream implementation.
    The new implementation is much faster for big files given it does not need to keep in memory the whole file.
    Covered by existing tests.

    * fileapi/Blob.cpp:
    * fileapi/FileReaderLoader.cpp:
    * fileapi/FileReaderLoader.h:
    * fileapi/FileReaderLoaderClient.h:

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

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (289294 => 289295)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:54:38 UTC (rev 289294)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-02-08 02:54:41 UTC (rev 289295)
@@ -1,5 +1,44 @@
 2022-02-07  Russell Epstein  <[email protected]>
 
+        Cherry-pick r288463. rdar://problem/87977499
+
+    file.stream() is slow and CPU-bound
+    https://bugs.webkit.org/show_bug.cgi?id=235448
+    
+    Reviewed by Alex Christensen.
+    
+    We introduce a ReadAsBinaryChunks mode to prevent storing the whole file in memory.
+    Use this in Blob stream implementation.
+    The new implementation is much faster for big files given it does not need to keep in memory the whole file.
+    Covered by existing tests.
+    
+    * fileapi/Blob.cpp:
+    * fileapi/FileReaderLoader.cpp:
+    * fileapi/FileReaderLoader.h:
+    * fileapi/FileReaderLoaderClient.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288463 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-01-24  Youenn Fablet  <[email protected]>
+
+            file.stream() is slow and CPU-bound
+            https://bugs.webkit.org/show_bug.cgi?id=235448
+
+            Reviewed by Alex Christensen.
+
+            We introduce a ReadAsBinaryChunks mode to prevent storing the whole file in memory.
+            Use this in Blob stream implementation.
+            The new implementation is much faster for big files given it does not need to keep in memory the whole file.
+            Covered by existing tests.
+
+            * fileapi/Blob.cpp:
+            * fileapi/FileReaderLoader.cpp:
+            * fileapi/FileReaderLoader.h:
+            * fileapi/FileReaderLoaderClient.h:
+
+2022-02-07  Russell Epstein  <[email protected]>
+
         Cherry-pick r288439. rdar://problem/88592095
 
     Reconfiguring the CoreAudioSharedUnit should take into account that there is a speaker sample producer

Modified: branches/safari-613-branch/Source/WebCore/fileapi/Blob.cpp (289294 => 289295)


--- branches/safari-613-branch/Source/WebCore/fileapi/Blob.cpp	2022-02-08 02:54:38 UTC (rev 289294)
+++ branches/safari-613-branch/Source/WebCore/fileapi/Blob.cpp	2022-02-08 02:54:41 UTC (rev 289295)
@@ -241,7 +241,7 @@
     class BlobStreamSource : public FileReaderLoaderClient, public ReadableStreamSource {
     public:
         BlobStreamSource(ScriptExecutionContext& scriptExecutionContext, Blob& blob)
-            : m_loader(makeUniqueRef<FileReaderLoader>(FileReaderLoader::ReadType::ReadAsArrayBuffer, this))
+            : m_loader(makeUniqueRef<FileReaderLoader>(FileReaderLoader::ReadType::ReadAsBinaryChunks, this))
         {
             m_loader->start(&scriptExecutionContext, blob);
         }
@@ -265,19 +265,11 @@
 
         // FileReaderLoaderClient
         void didStartLoading() final { }
-        void didReceiveData() final
+        void didReceiveData() final { }
+        void didReceiveBinaryChunk(const SharedBuffer& buffer) final
         {
-            auto result = m_loader->arrayBufferResult();
-            if (!result)
-                return;
-
-            if (m_loader->isCompleted() && !m_bytesRead)
-                controller().enqueue(WTFMove(result));
-            else {
-                auto bytesLoaded = m_loader->bytesLoaded();
-                controller().enqueue(result->slice(m_bytesRead, bytesLoaded));
-                m_bytesRead = bytesLoaded;
-            }
+            if (!controller().enqueue(buffer.tryCreateArrayBuffer()))
+                doCancel();
         }
         void didFinishLoading() final
         {
@@ -294,7 +286,6 @@
         }
 
         UniqueRef<FileReaderLoader> m_loader;
-        size_t m_bytesRead { 0 };
         bool m_isStarted { false };
         std::optional<Exception> m_exception;
     };

Modified: branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.cpp (289294 => 289295)


--- branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.cpp	2022-02-08 02:54:38 UTC (rev 289294)
+++ branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.cpp	2022-02-08 02:54:41 UTC (rev 289295)
@@ -177,6 +177,12 @@
     if (m_errorCode)
         return;
 
+    if (m_readType == ReadType::ReadAsBinaryChunks) {
+        if (m_client)
+            m_client->didReceiveBinaryChunk(buffer);
+        return;
+    }
+
     int length = buffer.size();
     unsigned remainingBufferSpace = m_totalBytes - m_bytesLoaded;
     if (length > static_cast<long long>(remainingBufferSpace)) {
@@ -311,7 +317,8 @@
         if (isCompleted())
             convertToDataURL();
         break;
-    default:
+    case ReadAsBlob:
+    case ReadAsBinaryChunks:
         ASSERT_NOT_REACHED();
     }
     

Modified: branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.h (289294 => 289295)


--- branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.h	2022-02-08 02:54:38 UTC (rev 289294)
+++ branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoader.h	2022-02-08 02:54:41 UTC (rev 289295)
@@ -58,7 +58,8 @@
         ReadAsBinaryString,
         ReadAsBlob,
         ReadAsText,
-        ReadAsDataURL
+        ReadAsDataURL,
+        ReadAsBinaryChunks
     };
 
     // If client is given, do the loading asynchronously. Otherwise, load synchronously.

Modified: branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoaderClient.h (289294 => 289295)


--- branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoaderClient.h	2022-02-08 02:54:38 UTC (rev 289294)
+++ branches/safari-613-branch/Source/WebCore/fileapi/FileReaderLoaderClient.h	2022-02-08 02:54:41 UTC (rev 289295)
@@ -41,6 +41,7 @@
 
     virtual void didStartLoading() = 0;
     virtual void didReceiveData() = 0;
+    virtual void didReceiveBinaryChunk(const SharedBuffer&) { }
     virtual void didFinishLoading() = 0;
     virtual void didFail(ExceptionCode errorCode) = 0;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to