Ensure that the Web Content process doesn't sleep during initialization
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2018 21:53:17 +0000 (21:53 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2018 21:53:17 +0000 (21:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185975
<rdar://problem/40548159>

Reviewed by Geoffrey Garen.

WebProcessPool::warmInitialProcess isn't worth much (or at least, as much
as it could be) if the Web Content process goes to sleep in the middle
of initializeWebProcess.

Keep the Web Content process alive until it has handled all messages
sent from WebProcessPool::initializeNewWebProcess.

This is a significant speedup on some benchmarks I've been running
that involve prewarming a process long before any content is loaded.

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebProcessPool.cpp

index 8b0dec1..7908599 100644 (file)
@@ -1,3 +1,24 @@
+2018-05-25  Tim Horton  <timothy_horton@apple.com>
+
+        Ensure that the Web Content process doesn't sleep during initialization
+        https://bugs.webkit.org/show_bug.cgi?id=185975
+        <rdar://problem/40548159>
+
+        Reviewed by Geoffrey Garen.
+
+        WebProcessPool::warmInitialProcess isn't worth much (or at least, as much
+        as it could be) if the Web Content process goes to sleep in the middle
+        of initializeWebProcess.
+
+        Keep the Web Content process alive until it has handled all messages
+        sent from WebProcessPool::initializeNewWebProcess.
+
+        This is a significant speedup on some benchmarks I've been running
+        that involve prewarming a process long before any content is loaded.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+
 2018-05-25  Chris Dumez  <cdumez@apple.com>
 
         WebsiteDataStore::enableResourceLoadStatisticsAndSetTestingCallback() unexpectedly constructs a process pool
index 067a5b5..a79c256 100644 (file)
@@ -93,6 +93,7 @@
 #include <wtf/NeverDestroyed.h>
 #include <wtf/ProcessPrivilege.h>
 #include <wtf/RunLoop.h>
+#include <wtf/Scope.h>
 #include <wtf/WallTime.h>
 #include <wtf/text/StringBuilder.h>
 
@@ -832,6 +833,14 @@ static void registerDisplayConfigurationCallback()
 
 void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDataStore& websiteDataStore)
 {
+    auto initializationActivityToken = process.throttler().backgroundActivityToken();
+    auto scopeExit = makeScopeExit([&process, initializationActivityToken] {
+        // Round-trip to the Web Content process before releasing the
+        // initialization activity token, so that we're sure that all
+        // messages sent from this function have been handled.
+        process.isResponsive([initializationActivityToken] (bool) { });
+    });
+
     ensureNetworkProcess();
 
     WebProcessCreationParameters parameters;