[iOS] WebProcess::initializeWebProcess spends ~150ms spinning up AVSystemController...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Oct 2017 02:20:19 +0000 (02:20 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Oct 2017 02:20:19 +0000 (02:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178640
<rdar://problem/35113105>

Reviewed by Youenn Fablet.

In r213933, we added a mechanism to allow the web process to drive media capture, by setting an attribute on the
shared AVSystemController. This requires us to fault in the Celestial framework, which is a slight performance
hit on some hardware. Instead of doing this at the start of every web process launch, we can just do this work
lazily, the first time the web process requests permissions for user media access.

* WebProcess/WebCoreSupport/WebUserMediaClient.cpp:
(WebKit::WebUserMediaClient::requestUserMediaAccess):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebCoreSupport/WebUserMediaClient.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

index d5c45e7..61354a3 100644 (file)
@@ -1,3 +1,26 @@
+2017-10-22  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] WebProcess::initializeWebProcess spends ~150ms spinning up AVSystemController on some devices
+        https://bugs.webkit.org/show_bug.cgi?id=178640
+        <rdar://problem/35113105>
+
+        Reviewed by Youenn Fablet.
+
+        In r213933, we added a mechanism to allow the web process to drive media capture, by setting an attribute on the
+        shared AVSystemController. This requires us to fault in the Celestial framework, which is a slight performance
+        hit on some hardware. Instead of doing this at the start of every web process launch, we can just do this work
+        lazily, the first time the web process requests permissions for user media access.
+
+        * WebProcess/WebCoreSupport/WebUserMediaClient.cpp:
+        (WebKit::WebUserMediaClient::requestUserMediaAccess):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::prepareToSendUserMediaPermissionRequest):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2017-10-21  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, silence a -Wunused-but-set-variable warning
index 2a019a0..6f60574 100644 (file)
@@ -43,6 +43,7 @@ void WebUserMediaClient::pageDestroyed()
 
 void WebUserMediaClient::requestUserMediaAccess(UserMediaRequest& request)
 {
+    m_page.prepareToSendUserMediaPermissionRequest();
     m_page.userMediaPermissionRequestManager().startUserMediaRequest(request);
 }
 
index ad8070d..2f3876d 100644 (file)
@@ -3898,6 +3898,13 @@ void WebPage::didReceiveNotificationPermissionDecision(uint64_t notificationID,
 }
 
 #if ENABLE(MEDIA_STREAM)
+
+#if !PLATFORM(IOS)
+void WebPage::prepareToSendUserMediaPermissionRequest()
+{
+}
+#endif
+
 void WebPage::userMediaAccessWasGranted(uint64_t userMediaID, String&& audioDeviceUID, String&& videoDeviceUID, String&& mediaDeviceIdentifierHashSalt)
 {
     m_userMediaPermissionRequestManager->userMediaAccessWasGranted(userMediaID, WTFMove(audioDeviceUID), WTFMove(videoDeviceUID), WTFMove(mediaDeviceIdentifierHashSalt));
index a179bdb..66f5916 100644 (file)
@@ -511,6 +511,7 @@ public:
 
 #if ENABLE(MEDIA_STREAM)
     UserMediaPermissionRequestManager& userMediaPermissionRequestManager() { return *m_userMediaPermissionRequestManager; }
+    void prepareToSendUserMediaPermissionRequest();
 #endif
 
     void elementDidFocus(WebCore::Node*);
index 0f27852..bcb6988 100644 (file)
@@ -99,6 +99,7 @@
 #import <WebCore/RenderImage.h>
 #import <WebCore/RenderThemeIOS.h>
 #import <WebCore/RenderView.h>
+#import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/Settings.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/StyleProperties.h>
 #import <wtf/MathExtras.h>
 #import <wtf/MemoryPressureHandler.h>
 #import <wtf/SetForScope.h>
+#import <wtf/SoftLinking.h>
 #import <wtf/text/TextStream.h>
 
+#if ENABLE(MEDIA_STREAM)
+#import "CelestialSPI.h"
+SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Celestial)
+SOFT_LINK_CLASS_OPTIONAL(Celestial, AVSystemController)
+SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_PIDToInheritApplicationStateFrom, NSString *)
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -3411,6 +3420,22 @@ void WebPage::didReceivePasswordForQuickLookDocument(const String& password)
 }
 #endif
 
+#if ENABLE(MEDIA_STREAM)
+void WebPage::prepareToSendUserMediaPermissionRequest()
+{
+    static std::once_flag once;
+    std::call_once(once, [] {
+        if (!canLoadAVSystemController_PIDToInheritApplicationStateFrom())
+            return;
+
+        NSError *error = nil;
+        [[getAVSystemControllerClass() sharedAVSystemController] setAttribute:@(WebCore::presentingApplicationPID()) forKey:getAVSystemController_PIDToInheritApplicationStateFrom() error:&error];
+        if (error)
+            WTFLogAlways("Failed to set up PID proxying: %s", error.localizedDescription.UTF8String);
+    });
+}
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)
index e376e46..963aa73 100644 (file)
 #import <stdio.h>
 
 #if PLATFORM(IOS)
-#import "CelestialSPI.h"
 #import <pal/spi/ios/GraphicsServicesSPI.h>
-#import <wtf/SoftLinking.h>
 #endif
 
 #if USE(OS_STATE)
 #import <os/state_private.h>
 #endif
 
-#if PLATFORM(IOS)
-SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(Celestial)
-
-SOFT_LINK_CLASS_OPTIONAL(Celestial, AVSystemController)
-
-SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_PIDToInheritApplicationStateFrom, NSString *)
-
-#define AVSystemController_PIDToInheritApplicationStateFrom getAVSystemController_PIDToInheritApplicationStateFrom()
-#endif
-
 using namespace WebCore;
 
 namespace WebKit {
@@ -175,16 +163,6 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters&& par
     // Priority decay on iOS 9 is impacting page load time so we fix the priority of the WebProcess' main thread (rdar://problem/22003112).
     pthread_set_fixedpriority_self();
 #endif
-
-#if PLATFORM(IOS)
-    if (canLoadAVSystemController_PIDToInheritApplicationStateFrom()) {
-        pid_t pid = WebCore::presentingApplicationPID();
-        NSError *error = nil;
-        [[getAVSystemControllerClass() sharedAVSystemController] setAttribute:@(pid) forKey:AVSystemController_PIDToInheritApplicationStateFrom error:&error];
-        if (error)
-            WTFLogAlways("Failed to set up PID proxying: %s", [[error localizedDescription] UTF8String]);
-    }
-#endif
 }
 
 void WebProcess::initializeProcessName(const ChildProcessInitializationParameters& parameters)