<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[185452] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/185452">185452</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-06-11 05:05:25 -0700 (Thu, 11 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>3% cold PLT regression from network cache on iOS
https://bugs.webkit.org/show_bug.cgi?id=145694
rdar://problem/21158245

Reviewed by Chris Dumez.

Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.

* NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
(WebKit::NetworkCache::IOChannel::IOChannel):
(WebKit::NetworkCache::IOChannel::open):

    Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.

* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
(WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):

    Only write one file at a time instead of maximum of three.

(WebKit::NetworkCache::Storage::retrieve):

    For consistency with store prepend new entries here too.

(WebKit::NetworkCache::Storage::store):

    Delay start of the first write operation by 1s.
    Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates

(WebKit::NetworkCache::Storage::traverse):
* NetworkProcess/cache/NetworkCacheStorage.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheIOChannelCocoamm">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (185451 => 185452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/ChangeLog        2015-06-11 12:05:25 UTC (rev 185452)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2015-06-11  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        3% cold PLT regression from network cache on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=145694
+        rdar://problem/21158245
+
+        Reviewed by Chris Dumez.
+
+        Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.
+
+        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+        (WebKit::NetworkCache::IOChannel::IOChannel):
+        (WebKit::NetworkCache::IOChannel::open):
+
+            Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.
+
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::Storage):
+        (WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
+        (WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):
+
+            Only write one file at a time instead of maximum of three.
+
+        (WebKit::NetworkCache::Storage::retrieve):
+
+            For consistency with store prepend new entries here too.
+
+        (WebKit::NetworkCache::Storage::store):
+
+            Delay start of the first write operation by 1s.
+            Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates
+
+        (WebKit::NetworkCache::Storage::traverse):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+
</ins><span class="cx"> 2015-06-10  Yongjun Zhang  &lt;yongjun_zhang@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Don't send touch events on link preview.
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheIOChannelCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm (185451 => 185452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm        2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm        2015-06-11 12:05:25 UTC (rev 185452)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx">     auto path = WebCore::fileSystemRepresentation(filePath);
</span><span class="cx">     int oflag;
</span><span class="cx">     mode_t mode;
</span><ins>+    bool useLowIOPriority = false;
</ins><span class="cx"> 
</span><span class="cx">     switch (m_type) {
</span><span class="cx">     case Type::Create:
</span><span class="lines">@@ -53,10 +54,12 @@
</span><span class="cx">         unlink(path.data());
</span><span class="cx">         oflag = O_RDWR | O_CREAT | O_NONBLOCK;
</span><span class="cx">         mode = S_IRUSR | S_IWUSR;
</span><ins>+        useLowIOPriority = true;
</ins><span class="cx">         break;
</span><span class="cx">     case Type::Write:
</span><span class="cx">         oflag = O_WRONLY | O_NONBLOCK;
</span><span class="cx">         mode = S_IRUSR | S_IWUSR;
</span><ins>+        useLowIOPriority = true;
</ins><span class="cx">         break;
</span><span class="cx">     case Type::Read:
</span><span class="cx">         oflag = O_RDONLY | O_NONBLOCK;
</span><span class="lines">@@ -70,8 +73,14 @@
</span><span class="cx">         close(fd);
</span><span class="cx">     }));
</span><span class="cx">     ASSERT(m_dispatchIO.get());
</span><ins>+
</ins><span class="cx">     // This makes the channel read/write all data before invoking the handlers.
</span><span class="cx">     dispatch_io_set_low_water(m_dispatchIO.get(), std::numeric_limits&lt;size_t&gt;::max());
</span><ins>+
+    if (useLowIOPriority) {
+        // The target queue of a dispatch I/O channel specifies the priority of the global queue where its I/O operations are executed.
+        dispatch_set_target_queue(m_dispatchIO.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Ref&lt;IOChannel&gt; IOChannel::open(const String&amp; filePath, IOChannel::Type type)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (185451 => 185452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-06-11 12:05:25 UTC (rev 185452)
</span><span class="lines">@@ -126,6 +126,7 @@
</span><span class="cx"> Storage::Storage(const String&amp; baseDirectoryPath)
</span><span class="cx">     : m_basePath(baseDirectoryPath)
</span><span class="cx">     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
</span><ins>+    , m_writeOperationDispatchTimer(*this, &amp;Storage::dispatchPendingWriteOperations)
</ins><span class="cx">     , m_ioQueue(WorkQueue::create(&quot;com.apple.WebKit.Cache.Storage&quot;, WorkQueue::Type::Concurrent))
</span><span class="cx">     , m_backgroundIOQueue(WorkQueue::create(&quot;com.apple.WebKit.Cache.Storage.background&quot;, WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
</span><span class="cx">     , m_serialBackgroundIOQueue(WorkQueue::create(&quot;com.apple.WebKit.Cache.Storage.serialBackground&quot;, WorkQueue::Type::Serial, WorkQueue::QOS::Background))
</span><span class="lines">@@ -543,7 +544,7 @@
</span><span class="cx">         auto&amp; pendingRetrieveQueue = m_pendingReadOperationsByPriority[priority];
</span><span class="cx">         if (pendingRetrieveQueue.isEmpty())
</span><span class="cx">             continue;
</span><del>-        auto readOperation = pendingRetrieveQueue.takeFirst();
</del><ins>+        auto readOperation = pendingRetrieveQueue.takeLast();
</ins><span class="cx">         auto&amp; read = *readOperation;
</span><span class="cx">         m_activeReadOperations.add(WTF::move(readOperation));
</span><span class="cx">         dispatchReadOperation(read);
</span><span class="lines">@@ -569,14 +570,14 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><del>-    const int maximumActiveWriteOperationCount { 3 };
</del><ins>+    const int maximumActiveWriteOperationCount { 1 };
</ins><span class="cx"> 
</span><span class="cx">     while (!m_pendingWriteOperations.isEmpty()) {
</span><span class="cx">         if (m_activeWriteOperations.size() &gt;= maximumActiveWriteOperationCount) {
</span><span class="cx">             LOG(NetworkCacheStorage, &quot;(NetworkProcess) limiting parallel writes&quot;);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        auto writeOperation = m_pendingWriteOperations.takeFirst();
</del><ins>+        auto writeOperation = m_pendingWriteOperations.takeLast();
</ins><span class="cx">         auto&amp; write = *writeOperation;
</span><span class="cx">         m_activeWriteOperations.add(WTF::move(writeOperation));
</span><span class="cx"> 
</span><span class="lines">@@ -659,7 +660,7 @@
</span><span class="cx">     if (retrieveFromMemory(m_activeWriteOperations, key, completionHandler))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_pendingReadOperationsByPriority[priority].append(new ReadOperation { key, WTF::move(completionHandler) } );
</del><ins>+    m_pendingReadOperationsByPriority[priority].prepend(new ReadOperation { key, WTF::move(completionHandler) } );
</ins><span class="cx">     dispatchPendingReadOperations();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -671,12 +672,19 @@
</span><span class="cx">     if (!m_capacity)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_pendingWriteOperations.append(new WriteOperation { record, WTF::move(mappedBodyHandler) });
</del><ins>+    m_pendingWriteOperations.prepend(new WriteOperation { record, WTF::move(mappedBodyHandler) });
</ins><span class="cx"> 
</span><span class="cx">     // Add key to the filter already here as we do lookups from the pending operations too.
</span><span class="cx">     addToRecordFilter(record.key);
</span><span class="cx"> 
</span><del>-    dispatchPendingWriteOperations();
</del><ins>+    bool isInitialWrite = m_pendingWriteOperations.size() == 1;
+    if (!isInitialWrite)
+        return;
+
+    // Delay the start of writes a bit to avoid affecting early page load.
+    // Completing writes will dispatch more writes without delay.
+    static const auto initialWriteDelay = 1_s;
+    m_writeOperationDispatchTimer.startOneShot(initialWriteDelay);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Storage::traverse(TraverseFlags flags, TraverseHandler&amp;&amp; traverseHandler)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (185451 => 185452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-06-11 09:30:55 UTC (rev 185451)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-06-11 12:05:25 UTC (rev 185452)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;NetworkCacheBlobStorage.h&quot;
</span><span class="cx"> #include &quot;NetworkCacheData.h&quot;
</span><span class="cx"> #include &quot;NetworkCacheKey.h&quot;
</span><ins>+#include &lt;WebCore/Timer.h&gt;
</ins><span class="cx"> #include &lt;wtf/BloomFilter.h&gt;
</span><span class="cx"> #include &lt;wtf/Deque.h&gt;
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="lines">@@ -150,6 +151,7 @@
</span><span class="cx"> 
</span><span class="cx">     Deque&lt;std::unique_ptr&lt;WriteOperation&gt;&gt; m_pendingWriteOperations;
</span><span class="cx">     HashSet&lt;std::unique_ptr&lt;WriteOperation&gt;&gt; m_activeWriteOperations;
</span><ins>+    WebCore::Timer m_writeOperationDispatchTimer;
</ins><span class="cx"> 
</span><span class="cx">     Ref&lt;WorkQueue&gt; m_ioQueue;
</span><span class="cx">     Ref&lt;WorkQueue&gt; m_backgroundIOQueue;
</span></span></pre>
</div>
</div>

</body>
</html>