Changeset 241821 in webkit


Ignore:
Timestamp:
Feb 20, 2019 10:34:44 AM (5 years ago)
Author:
Chris Dumez
Message:

[WKTR] Avoid starting new NetworkProcesses unnecessarily when running the layout tests
https://bugs.webkit.org/show_bug.cgi?id=194829
<rdar://problem/47889906>

Reviewed by Alexey Proskuryakov.

Every time the TestOptions were changing we were creating both a new Web view and
a new WKContext, which would start a new Network process. In most cases, we only
need to contruct a new Web view and we do can keep reusing the same WKContext.
This patch implements this optimization and thus avoids spinning a lot of new
Network processes while running the layout tests.

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::generateContextConfiguration const):
(WTR::TestController::generatePageConfiguration):
(WTR::TestController::createWebViewWithOptions):
(WTR::TestController::resetPreferencesToConsistentValues):
(WTR::updateTestOptionsFromTestHeader):

  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestOptions.h:

(WTR::TestOptions::ContextOptions::hasSameInitializationOptions const):
(WTR::TestOptions::ContextOptions::shouldEnableProcessSwapOnNavigation const):
(WTR::TestOptions::hasSameInitializationOptions const):
(WTR::TestOptions::shouldEnableProcessSwapOnNavigation const): Deleted.

  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::TestController::platformAddTestOptions const):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r241790 r241821  
     12019-02-20  Chris Dumez  <cdumez@apple.com>
     2
     3        [WKTR] Avoid starting new NetworkProcesses unnecessarily when running the layout tests
     4        https://bugs.webkit.org/show_bug.cgi?id=194829
     5        <rdar://problem/47889906>
     6
     7        Reviewed by Alexey Proskuryakov.
     8
     9        Every time the TestOptions were changing we were creating both a new Web view and
     10        a new WKContext, which would start a new Network process. In most cases, we only
     11        need to contruct a new Web view and we do can keep reusing the same WKContext.
     12        This patch implements this optimization and thus avoids spinning a lot of new
     13        Network processes while running the layout tests.
     14
     15        * WebKitTestRunner/TestController.cpp:
     16        (WTR::TestController::generateContextConfiguration const):
     17        (WTR::TestController::generatePageConfiguration):
     18        (WTR::TestController::createWebViewWithOptions):
     19        (WTR::TestController::resetPreferencesToConsistentValues):
     20        (WTR::updateTestOptionsFromTestHeader):
     21        * WebKitTestRunner/TestController.h:
     22        * WebKitTestRunner/TestOptions.h:
     23        (WTR::TestOptions::ContextOptions::hasSameInitializationOptions const):
     24        (WTR::TestOptions::ContextOptions::shouldEnableProcessSwapOnNavigation const):
     25        (WTR::TestOptions::hasSameInitializationOptions const):
     26        (WTR::TestOptions::shouldEnableProcessSwapOnNavigation const): Deleted.
     27        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     28        (WTR::TestController::platformAddTestOptions const):
     29
    1302019-02-20  Adrian Perez de Castro  <aperez@igalia.com>
    231
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r241654 r241821  
    455455}
    456456
    457 WKRetainPtr<WKContextConfigurationRef> TestController::generateContextConfiguration(const TestOptions& options) const
     457WKRetainPtr<WKContextConfigurationRef> TestController::generateContextConfiguration(const TestOptions::ContextOptions& options) const
    458458{
    459459    auto configuration = adoptWK(WKContextConfigurationCreate());
     
    461461    WKContextConfigurationSetFullySynchronousModeIsAllowedForTesting(configuration.get(), true);
    462462    WKContextConfigurationSetIgnoreSynchronousMessagingTimeoutsForTesting(configuration.get(), options.ignoreSynchronousMessagingTimeouts);
     463
     464    WKRetainPtr<WKMutableArrayRef> overrideLanguages = adoptWK(WKMutableArrayCreate());
     465    for (auto& language : options.overrideLanguages)
     466        WKArrayAppendItem(overrideLanguages.get(), adoptWK(WKStringCreateWithUTF8CString(language.utf8().data())).get());
     467    WKContextConfigurationSetOverrideLanguages(configuration.get(), overrideLanguages.get());
     468
     469    if (options.shouldEnableProcessSwapOnNavigation()) {
     470        WKContextConfigurationSetProcessSwapsOnNavigation(configuration.get(), true);
     471        if (options.enableProcessSwapOnWindowOpen)
     472            WKContextConfigurationSetProcessSwapsOnWindowOpenWithOpener(configuration.get(), true);
     473    }
    463474
    464475    if (const char* dumpRenderTreeTemp = libraryPathForTesting()) {
     
    476487}
    477488
    478 WKRetainPtr<WKPageConfigurationRef> TestController::generatePageConfiguration(WKContextConfigurationRef configuration)
    479 {
    480     m_context = platformAdjustContext(adoptWK(WKContextCreateWithConfiguration(configuration)).get(), configuration);
    481 
    482     m_geolocationProvider = std::make_unique<GeolocationProviderMock>(m_context.get());
    483 
    484     if (const char* dumpRenderTreeTemp = libraryPathForTesting()) {
    485         String temporaryFolder = String::fromUTF8(dumpRenderTreeTemp);
    486 
    487         // FIXME: This should be migrated to WKContextConfigurationRef.
    488         // Disable icon database to avoid fetching <http://127.0.0.1:8000/favicon.ico> and making tests flaky.
    489         // Invividual tests can enable it using testRunner.setIconDatabaseEnabled, although it's not currently supported in WebKitTestRunner.
    490         WKContextSetIconDatabasePath(m_context.get(), toWK(emptyString()).get());
    491     }
    492 
    493     WKContextSetDiskCacheSpeculativeValidationEnabled(m_context.get(), true);
    494     WKContextUseTestingNetworkSession(m_context.get());
    495     WKContextSetCacheModel(m_context.get(), kWKCacheModelDocumentBrowser);
    496 
    497     auto* websiteDataStore = WKContextGetWebsiteDataStore(m_context.get());
    498     WKWebsiteDataStoreSetCacheStoragePerOriginQuota(websiteDataStore, 400 * 1024);
    499    
    500     platformInitializeContext();
     489WKRetainPtr<WKPageConfigurationRef> TestController::generatePageConfiguration(const TestOptions& options)
     490{
     491    if (!m_context || !m_contextOptions->hasSameInitializationOptions(options.contextOptions)) {
     492        auto contextConfiguration = generateContextConfiguration(options.contextOptions);
     493        m_context = platformAdjustContext(adoptWK(WKContextCreateWithConfiguration(contextConfiguration.get())).get(), contextConfiguration.get());
     494        m_contextOptions = options.contextOptions;
     495
     496        m_geolocationProvider = std::make_unique<GeolocationProviderMock>(m_context.get());
     497
     498        if (const char* dumpRenderTreeTemp = libraryPathForTesting()) {
     499            String temporaryFolder = String::fromUTF8(dumpRenderTreeTemp);
     500
     501            // FIXME: This should be migrated to WKContextConfigurationRef.
     502            // Disable icon database to avoid fetching <http://127.0.0.1:8000/favicon.ico> and making tests flaky.
     503            // Invividual tests can enable it using testRunner.setIconDatabaseEnabled, although it's not currently supported in WebKitTestRunner.
     504            WKContextSetIconDatabasePath(m_context.get(), toWK(emptyString()).get());
     505        }
     506
     507        WKContextSetDiskCacheSpeculativeValidationEnabled(m_context.get(), true);
     508        WKContextUseTestingNetworkSession(m_context.get());
     509        WKContextSetCacheModel(m_context.get(), kWKCacheModelDocumentBrowser);
     510
     511        auto* websiteDataStore = WKContextGetWebsiteDataStore(m_context.get());
     512        WKWebsiteDataStoreSetCacheStoragePerOriginQuota(websiteDataStore, 400 * 1024);
     513
     514        platformInitializeContext();
     515    }
    501516
    502517    WKContextInjectedBundleClientV1 injectedBundleClient = {
     
    548563void TestController::createWebViewWithOptions(const TestOptions& options)
    549564{
    550     auto contextConfiguration = generateContextConfiguration(options);
    551 
    552     WKRetainPtr<WKMutableArrayRef> overrideLanguages = adoptWK(WKMutableArrayCreate());
    553     for (auto& language : options.overrideLanguages)
    554         WKArrayAppendItem(overrideLanguages.get(), adoptWK(WKStringCreateWithUTF8CString(language.utf8().data())).get());
    555     WKContextConfigurationSetOverrideLanguages(contextConfiguration.get(), overrideLanguages.get());
    556 
    557     if (options.shouldEnableProcessSwapOnNavigation()) {
    558         WKContextConfigurationSetProcessSwapsOnNavigation(contextConfiguration.get(), true);
    559         if (options.enableProcessSwapOnWindowOpen)
    560             WKContextConfigurationSetProcessSwapsOnWindowOpenWithOpener(contextConfiguration.get(), true);
    561     }
    562 
    563     auto configuration = generatePageConfiguration(contextConfiguration.get());
     565    auto configuration = generatePageConfiguration(options);
    564566
    565567    // Some preferences (notably mock scroll bars setting) currently cannot be re-applied to an existing view, so we need to set them now.
     
    737739        WKPreferencesSetInternalDebugFeatureForKey(preferences, internalDebugFeature.value, toWK(internalDebugFeature.key).get());
    738740
    739     WKPreferencesSetProcessSwapOnNavigationEnabled(preferences, options.shouldEnableProcessSwapOnNavigation());
     741    WKPreferencesSetProcessSwapOnNavigationEnabled(preferences, options.contextOptions.shouldEnableProcessSwapOnNavigation());
    740742    WKPreferencesSetPageVisibilityBasedProcessSuppressionEnabled(preferences, false);
    741743    WKPreferencesSetOfflineWebApplicationCacheEnabled(preferences, true);
     
    12301232
    12311233        if (key == "language")
    1232             testOptions.overrideLanguages = String(value.c_str()).split(',');
     1234            testOptions.contextOptions.overrideLanguages = String(value.c_str()).split(',');
    12331235        else if (key == "useThreadedScrolling")
    12341236            testOptions.useThreadedScrolling = parseBooleanTestHeaderValue(value);
     
    12741276            testOptions.domPasteAllowed = parseBooleanTestHeaderValue(value);
    12751277        else if (key == "enableProcessSwapOnNavigation")
    1276             testOptions.enableProcessSwapOnNavigation = parseBooleanTestHeaderValue(value);
     1278            testOptions.contextOptions.enableProcessSwapOnNavigation = parseBooleanTestHeaderValue(value);
    12771279        else if (key == "enableProcessSwapOnWindowOpen")
    1278             testOptions.enableProcessSwapOnWindowOpen = parseBooleanTestHeaderValue(value);
     1280            testOptions.contextOptions.enableProcessSwapOnWindowOpen = parseBooleanTestHeaderValue(value);
    12791281        else if (key == "enableColorFilter")
    12801282            testOptions.enableColorFilter = parseBooleanTestHeaderValue(value);
     
    12981300            testOptions.contentInsetTop = std::stod(value);
    12991301        else if (key == "ignoreSynchronousMessagingTimeouts")
    1300             testOptions.ignoreSynchronousMessagingTimeouts = parseBooleanTestHeaderValue(value);
     1302            testOptions.contextOptions.ignoreSynchronousMessagingTimeouts = parseBooleanTestHeaderValue(value);
    13011303        pairStart = pairEnd + 1;
    13021304    }
  • trunk/Tools/WebKitTestRunner/TestController.h

    r241654 r241821  
    2727
    2828#include "GeolocationProviderMock.h"
     29#include "TestOptions.h"
    2930#include "WebNotificationProvider.h"
    3031#include "WorkQueueManager.h"
     
    299300
    300301private:
    301     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
    302     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions&) const;
     302    WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(const TestOptions&);
     303    WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration(const TestOptions::ContextOptions&) const;
    303304    void initialize(int argc, const char* argv[]);
    304305    void createWebViewWithOptions(const TestOptions&);
     
    467468    std::unique_ptr<PlatformWebView> m_mainWebView;
    468469    WKRetainPtr<WKContextRef> m_context;
     470    Optional<TestOptions::ContextOptions> m_contextOptions;
    469471    WKRetainPtr<WKPageGroupRef> m_pageGroup;
    470472    WKRetainPtr<WKUserContentControllerRef> m_userContentController;
  • trunk/Tools/WebKitTestRunner/TestOptions.h

    r241322 r241821  
    3434
    3535struct TestOptions {
     36    struct ContextOptions {
     37        Vector<String> overrideLanguages;
     38        bool ignoreSynchronousMessagingTimeouts { false };
     39        bool enableProcessSwapOnNavigation { true };
     40        bool enableProcessSwapOnWindowOpen { false };
     41
     42        bool hasSameInitializationOptions(const ContextOptions& options) const
     43        {
     44            if (ignoreSynchronousMessagingTimeouts != options.ignoreSynchronousMessagingTimeouts
     45                || overrideLanguages != options.overrideLanguages
     46                || enableProcessSwapOnNavigation != options.enableProcessSwapOnNavigation
     47                || enableProcessSwapOnWindowOpen != options.enableProcessSwapOnWindowOpen)
     48                return false;
     49            return true;
     50        }
     51
     52        bool shouldEnableProcessSwapOnNavigation() const
     53        {
     54            return enableProcessSwapOnNavigation || enableProcessSwapOnWindowOpen;
     55        }
     56    };
     57
    3658    bool useThreadedScrolling { false };
    3759    bool useAcceleratedDrawing { false };
     
    5981    bool allowCrossOriginSubresourcesToAskForCredentials { false };
    6082    bool domPasteAllowed { true };
    61     bool enableProcessSwapOnNavigation { true };
    62     bool enableProcessSwapOnWindowOpen { false };
    6383    bool enableColorFilter { false };
    6484    bool punchOutWhiteBackgroundsInDarkMode { false };
     
    7090    bool editable { false };
    7191    bool enableUndoManagerAPI { false };
    72     bool ignoreSynchronousMessagingTimeouts { false };
    7392
    7493    double contentInsetTop { 0 };
    7594
    7695    float deviceScaleFactor { 1 };
    77     Vector<String> overrideLanguages;
    7896    std::string applicationManifest;
    7997    std::string jscOptions;
    8098    HashMap<String, bool> experimentalFeatures;
    8199    HashMap<String, bool> internalDebugFeatures;
     100
     101    ContextOptions contextOptions;
    82102
    83103    TestOptions(const std::string& pathOrURL);
     
    91111        if (useThreadedScrolling != options.useThreadedScrolling
    92112            || useAcceleratedDrawing != options.useAcceleratedDrawing
    93             || overrideLanguages != options.overrideLanguages
    94113            || useMockScrollbars != options.useMockScrollbars
    95114            || needsSiteSpecificQuirks != options.needsSiteSpecificQuirks
     
    108127            || allowCrossOriginSubresourcesToAskForCredentials != options.allowCrossOriginSubresourcesToAskForCredentials
    109128            || domPasteAllowed != options.domPasteAllowed
    110             || enableProcessSwapOnNavigation != options.enableProcessSwapOnNavigation
    111             || enableProcessSwapOnWindowOpen != options.enableProcessSwapOnWindowOpen
    112129            || enableColorFilter != options.enableColorFilter
    113130            || punchOutWhiteBackgroundsInDarkMode != options.punchOutWhiteBackgroundsInDarkMode
     
    120137            || editable != options.editable
    121138            || enableUndoManagerAPI != options.enableUndoManagerAPI
    122             || contentInsetTop != options.contentInsetTop
    123             || ignoreSynchronousMessagingTimeouts != options.ignoreSynchronousMessagingTimeouts)
     139            || contentInsetTop != options.contentInsetTop)
     140            return false;
     141
     142        if (!contextOptions.hasSameInitializationOptions(options.contextOptions))
    124143            return false;
    125144
     
    132151        return true;
    133152    }
    134    
    135     bool shouldEnableProcessSwapOnNavigation() const
    136     {
    137         return enableProcessSwapOnNavigation || enableProcessSwapOnWindowOpen;
    138     }
    139153};
    140154
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r241654 r241821  
    143143{
    144144    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EnableProcessSwapOnNavigation"])
    145         options.enableProcessSwapOnNavigation = true;
     145        options.contextOptions.enableProcessSwapOnNavigation = true;
    146146    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EnableProcessSwapOnWindowOpen"])
    147         options.enableProcessSwapOnWindowOpen = true;
     147        options.contextOptions.enableProcessSwapOnWindowOpen = true;
    148148}
    149149
Note: See TracChangeset for help on using the changeset viewer.