Changeset 237735 in webkit
- Timestamp:
- Nov 2, 2018 8:59:23 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r237714 r237735 1 2018-11-02 Chris Dumez <cdumez@apple.com> 2 3 [PSON] Reuse SuspendedPages' process when possible, for performance 4 https://bugs.webkit.org/show_bug.cgi?id=191166 5 6 Reviewed by Geoffrey Garen. 7 8 When process-swapping check if there is an existing SuspendedPage for the domain we're going to. 9 If there is, use this SuspendedPage's process for the navigation instead of a fresh new process. 10 This change should be beneficial for performance as it: 11 - Avoids spinning up a new process (CPU & memory cost) 12 - Likely better leverages caches since this process already loaded this domain in the past 13 14 Due to current limitations, using a SuspendedPage's proxy may consume the SuspendedPage, which 15 means that it can no longer be used for PageCache on history navigations. We need to do this when 16 the SuspendedPageProxy in question was created for the current WebPageProxy because: 17 - This SuspendedPageProxy's process already has a suspended WebPage with this WebPageProxy's pageID 18 and 19 - We do not currently support having more than one WebPage with a given pageID within a single 20 WebProcess. 21 22 * UIProcess/SuspendedPageProxy.cpp: 23 (WebKit::SuspendedPageProxy::SuspendedPageProxy): 24 * UIProcess/SuspendedPageProxy.h: 25 * UIProcess/WebProcessPool.cpp: 26 (WebKit::WebProcessPool::processForNavigationInternal): 27 1 28 2018-11-01 Fujii Hironori <Hironori.Fujii@sony.com> 2 29 -
trunk/Source/WebKit/UIProcess/SuspendedPageProxy.cpp
r237467 r237735 79 79 , m_process(WTFMove(process)) 80 80 , m_mainFrameID(mainFrameID) 81 , m_ origin(SecurityOriginData::fromURL({ { }, item.url() }))81 , m_registrableDomain(toRegistrableDomain(URL(URL(), item.url()))) 82 82 { 83 83 item.setSuspendedPage(*this); -
trunk/Source/WebKit/UIProcess/SuspendedPageProxy.h
r237467 r237735 45 45 WebProcessProxy& process() { return m_process.get(); } 46 46 uint64_t mainFrameID() const { return m_mainFrameID; } 47 const WebCore::SecurityOriginData& origin() const { return m_origin; }47 const String& registrableDomain() const { return m_registrableDomain; } 48 48 49 49 void unsuspend(); … … 63 63 Ref<WebProcessProxy> m_process; 64 64 uint64_t m_mainFrameID; 65 WebCore::SecurityOriginData m_origin;65 String m_registrableDomain; 66 66 67 67 bool m_isSuspended { true }; -
trunk/Source/WebKit/UIProcess/WebProcessPool.cpp
r237700 r237735 2186 2186 reason = "Process swap was requested by the client"_s; 2187 2187 2188 auto registrableDomain = toRegistrableDomain(targetURL); 2188 2189 if (m_configuration->alwaysKeepAndReuseSwappedProcesses()) { 2189 auto registrableDomain = toRegistrableDomain(targetURL);2190 2190 LOG(ProcessSwapping, "(ProcessSwapping) Considering re-use of a previously cached process for domain %s", registrableDomain.utf8().data()); 2191 2191 … … 2197 2197 // In the case where this WebProcess has a SuspendedPageProxy for this WebPage, we can throw it away to support 2198 2198 // WebProcess re-use. 2199 // In the future it would be great to refactor-out this limitation. 2200 page.process().processPool().removeAllSuspendedPageProxiesForPage(page); 2199 // In the future it would be great to refactor-out this limitation (https://bugs.webkit.org/show_bug.cgi?id=191166). 2200 m_suspendedPages.removeAllMatching([&](auto& suspendedPage) { 2201 return &suspendedPage->page() == &page && &suspendedPage->process() == process; 2202 }); 2201 2203 2202 2204 return makeRef(*process); 2203 2205 } 2204 2206 } 2207 } 2208 2209 // Check if we have a suspended page for the given registrable domain and use its process if we do, for performance reasons. 2210 auto it = m_suspendedPages.findIf([&](auto& suspendedPage) { 2211 return suspendedPage->registrableDomain() == registrableDomain; 2212 }); 2213 if (it != m_suspendedPages.end()) { 2214 Ref<WebProcessProxy> process = (*it)->process(); 2215 2216 // FIXME: If the SuspendedPage is for this page, then we need to destroy the suspended page as we do not support having 2217 // multiple WebPages with the same ID in a given WebProcess currently (https://bugs.webkit.org/show_bug.cgi?id=191166). 2218 if (&(*it)->page() == &page) 2219 m_suspendedPages.remove(it); 2220 2221 if (&process->websiteDataStore() != &page.websiteDataStore()) 2222 process->send(Messages::WebProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()), 0); 2223 2224 return process; 2205 2225 } 2206 2226 -
trunk/Tools/ChangeLog
r237731 r237735 1 2018-11-02 Chris Dumez <cdumez@apple.com> 2 3 [PSON] Reuse SuspendedPages' process when possible, for performance 4 https://bugs.webkit.org/show_bug.cgi?id=191166 5 6 Reviewed by Geoffrey Garen. 7 8 Add API test coverage. 9 10 * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: 11 1 12 2018-11-02 Zalan Bujtas <zalan@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm
r237699 r237735 1524 1524 done = false; 1525 1525 1526 auto pid1= [webView _webProcessIdentifier];1526 auto webkitPID = [webView _webProcessIdentifier]; 1527 1527 1528 1528 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.apple.com/main.html"]]; … … 1532 1532 done = false; 1533 1533 1534 auto pid2 = [webView _webProcessIdentifier]; 1534 auto applePID = [webView _webProcessIdentifier]; 1535 1536 // Verify the web pages are in different processes 1537 EXPECT_NE(webkitPID, applePID); 1535 1538 1536 1539 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main.html"]]; … … 1542 1545 done = false; 1543 1546 1544 auto pid3 = [webView _webProcessIdentifier]; 1545 1546 // Verify the web pages are in different processes 1547 EXPECT_NE(pid1, pid2); 1548 EXPECT_NE(pid1, pid3); 1549 EXPECT_NE(pid2, pid3); 1547 // We should have gone back to the webkit.org process for this load since we reuse SuspendedPages' process when possible. 1548 EXPECT_EQ(webkitPID, [webView _webProcessIdentifier]); 1550 1549 1551 1550 // Verify the sessionStorage values were as expected … … 1553 1552 EXPECT_TRUE([receivedMessages.get()[0] isEqualToString:@""]); 1554 1553 EXPECT_TRUE([receivedMessages.get()[1] isEqualToString:@"I exist!"]); 1554 } 1555 1556 TEST(ProcessSwap, ReuseSuspendedProcess) 1557 { 1558 auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]); 1559 [processPoolConfiguration setProcessSwapsOnNavigation:YES]; 1560 auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]); 1561 1562 auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]); 1563 [webViewConfiguration setProcessPool:processPool.get()]; 1564 auto handler = adoptNS([[PSONScheme alloc] init]); 1565 [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"]; 1566 1567 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]); 1568 auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]); 1569 [webView setNavigationDelegate:delegate.get()]; 1570 1571 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main1.html"]]; 1572 [webView loadRequest:request]; 1573 1574 TestWebKitAPI::Util::run(&done); 1575 done = false; 1576 1577 auto webkitPID = [webView _webProcessIdentifier]; 1578 1579 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.apple.com/main1.html"]]; 1580 [webView loadRequest:request]; 1581 1582 TestWebKitAPI::Util::run(&done); 1583 done = false; 1584 1585 auto applePID = [webView _webProcessIdentifier]; 1586 1587 EXPECT_NE(webkitPID, applePID); 1588 1589 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main2.html"]]; 1590 [webView loadRequest:request]; 1591 1592 TestWebKitAPI::Util::run(&done); 1593 done = false; 1594 1595 // We should have gone back to the webkit.org process for this load since we reuse SuspendedPages' process when possible. 1596 EXPECT_EQ(webkitPID, [webView _webProcessIdentifier]); 1597 1598 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.apple.com/main2.html"]]; 1599 [webView loadRequest:request]; 1600 1601 TestWebKitAPI::Util::run(&done); 1602 done = false; 1603 1604 // We should have gone back to the apple.com process for this load since we reuse SuspendedPages' process when possible. 1605 EXPECT_EQ(applePID, [webView _webProcessIdentifier]); 1555 1606 } 1556 1607
Note: See TracChangeset
for help on using the changeset viewer.