Skip memcmp()ing fully downloaded resources after they become mmap()able.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jun 2014 22:22:40 +0000 (22:22 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jun 2014 22:22:40 +0000 (22:22 +0000)
<https://webkit.org/b/134362>

When we receive word that a downloaded resource is now available for mmap()ing
from the file system, we don't need to compare against the buffered data,
since even if there were a mismatch, the cached version should be the canonical one.

This was added as belt-and-suspenders while the supporting mechanism was being
developed in CFNetwork, and there's no evidence of a race today. This change
turns the runtime checks into debug-only assertions.

Saves ~300ms of main thread time on PLT.

Reviewed by Geoff Garen.

* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::tryReplaceEncodedData):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedResource.cpp

index 897cc3d..95a491b 100644 (file)
@@ -1,3 +1,23 @@
+2014-06-26  Andreas Kling  <akling@apple.com>
+
+        Skip memcmp()ing fully downloaded resources after they become mmap()able.
+        <https://webkit.org/b/134362>
+
+        When we receive word that a downloaded resource is now available for mmap()ing
+        from the file system, we don't need to compare against the buffered data,
+        since even if there were a mismatch, the cached version should be the canonical one.
+
+        This was added as belt-and-suspenders while the supporting mechanism was being
+        developed in CFNetwork, and there's no evidence of a race today. This change
+        turns the runtime checks into debug-only assertions.
+
+        Saves ~300ms of main thread time on PLT.
+
+        Reviewed by Geoff Garen.
+
+        * loader/cache/CachedResource.cpp:
+        (WebCore::CachedResource::tryReplaceEncodedData):
+
 2014-06-26  Jer Noble  <jer.noble@apple.com>
 
         [MSE] Refactoring: Use C++11 for-loops in SourceBuffer.
index 5d19177..9eb1bcb 100644 (file)
@@ -900,11 +900,9 @@ void CachedResource::tryReplaceEncodedData(PassRefPtr<SharedBuffer> newBuffer)
     
     if (!mayTryReplaceEncodedData())
         return;
-    
-    // Because the disk cache is asynchronous and racey with regards to the data we might be asked to replace,
-    // we need to verify that the new buffer has the same contents as our old buffer.
-    if (m_data->size() != newBuffer->size() || memcmp(m_data->data(), newBuffer->data(), m_data->size()))
-        return;
+
+    ASSERT(m_data->size() == newBuffer->size());
+    ASSERT(!memcmp(m_data->data(), newBuffer->data(), m_data->size()));
 
     m_data->tryReplaceSharedBufferContents(newBuffer.get());
 }