Changeset 255135 in webkit
- Timestamp:
- Jan 26, 2020 8:38:51 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 11 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r255133 r255135 1 2020-01-26 Chris Dumez <cdumez@apple.com> 2 3 Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com 4 https://bugs.webkit.org/show_bug.cgi?id=206438 5 6 Reviewed by Darin Adler. 7 8 Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com. When scrolling on reddit.com, 9 you frequently see 2 consecutive sync IPCs (WebPageProxy::BackForwardBackListCount then WebPageProxy::BackForwardForwardListCount) 10 from the WebContent process to the UIProcess. Those are bad for performance. This happens every time the script on the page accesses 11 history.length, which is unfortunate, since this history length rarely changes. 12 13 To address the issue, the following changes were made: 14 1. Merge BackForwardBackListCount / BackForwardForwardListCount IPCs into a single BackForwardListCounts IPC which returns both 15 the back & forward counts, since we often need both (e.g. when accessing history.length) and since gettings those counts is 16 very cheap compared to the cost of a sync IPC. 17 2. Cache those counts in WebBackForwardListProxy and blow away the cached counts whenever the back/forward list changes. In the 18 common case (where the back/forward list rarely changes), we now see a single sync IPC instead of many (verified on reddit.com). 19 20 No new tests, merely a performance improvement. 21 22 * UIProcess/WebPageProxy.cpp: 23 * UIProcess/WebPageProxy.h: 24 * UIProcess/WebPageProxy.messages.in: 25 * WebProcess/WebPage/WebBackForwardListProxy.cpp: 26 (WebKit::WebBackForwardListProxy::addItemFromUIProcess): 27 (WebKit::WebBackForwardListProxy::addItem): 28 (WebKit::WebBackForwardListProxy::goToItem): 29 (WebKit::WebBackForwardListProxy::backListCount const): 30 (WebKit::WebBackForwardListProxy::forwardListCount const): 31 (WebKit::WebBackForwardListProxy::cacheListCountsIfNecessary const): 32 (WebKit::WebBackForwardListProxy::clearCachedListCounts): 33 (WebKit::WebBackForwardListProxy::close): 34 (WebKit::WebBackForwardListProxy::clear): 35 * WebProcess/WebPage/WebBackForwardListProxy.h: 36 1 37 2020-01-26 youenn fablet <youenn@apple.com> 2 38 -
trunk/Source/WebKit/Shared/WebBackForwardListCounts.h
r255134 r255135 1 1 /* 2 * Copyright (C) 20 10, 2011Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #include <WebCore/BackForwardClient.h> 29 #include <WebCore/PageIdentifier.h> 30 #include <wtf/HashSet.h> 31 32 namespace WebCore { 33 struct BackForwardItemIdentifier; 34 } 28 #include "Decoder.h" 29 #include "Encoder.h" 30 #include <wtf/Optional.h> 35 31 36 32 namespace WebKit { 37 33 38 class WebPage; 34 struct WebBackForwardListCounts { 35 uint32_t backCount { 0 }; 36 uint32_t forwardCount { 0 }; 39 37 40 class WebBackForwardListProxy : public WebCore::BackForwardClient { 41 public: 42 static Ref<WebBackForwardListProxy> create(WebPage& page) { return adoptRef(*new WebBackForwardListProxy(page)); } 38 void encode(IPC::Encoder& encoder) const 39 { 40 encoder << backCount; 41 encoder << forwardCount; 42 } 43 43 44 static WebCore::HistoryItem* itemForID(const WebCore::BackForwardItemIdentifier&); 45 static void removeItem(const WebCore::BackForwardItemIdentifier&); 44 static Optional<WebBackForwardListCounts> decode(IPC::Decoder& decoder) 45 { 46 Optional<uint32_t> backCount; 47 decoder >> backCount; 48 if (!backCount) 49 return WTF::nullopt; 46 50 47 enum class OverwriteExistingItem { 48 Yes, 49 No 50 }; 51 void addItemFromUIProcess(const WebCore::BackForwardItemIdentifier&, Ref<WebCore::HistoryItem>&&, WebCore::PageIdentifier, OverwriteExistingItem); 51 Optional<uint32_t> forwardCount; 52 decoder >> forwardCount; 53 if (!forwardCount) 54 return WTF::nullopt; 52 55 53 void clear(); 54 55 private: 56 WebBackForwardListProxy(WebPage&); 57 58 void addItem(Ref<WebCore::HistoryItem>&&) override; 59 60 void goToItem(WebCore::HistoryItem&) override; 61 62 RefPtr<WebCore::HistoryItem> itemAtIndex(int) override; 63 unsigned backListCount() const override; 64 unsigned forwardListCount() const override; 65 66 void close() override; 67 68 WebPage* m_page; 56 return WebBackForwardListCounts { *backCount, *forwardCount }; 57 } 69 58 }; 70 59 -
trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp
r254884 r255135 335 335 } 336 336 337 void ProvisionalPageProxy::backForwardGoToItem(const WebCore::BackForwardItemIdentifier& identifier, CompletionHandler<void(SandboxExtension::Handle&& )>&& completionHandler)337 void ProvisionalPageProxy::backForwardGoToItem(const WebCore::BackForwardItemIdentifier& identifier, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler) 338 338 { 339 339 m_page.backForwardGoToItemShared(m_process.copyRef(), identifier, WTFMove(completionHandler)); -
trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h
r254884 r255135 124 124 void didFailProvisionalLoadForFrame(WebCore::FrameIdentifier, WebCore::SecurityOriginData&& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, WebCore::WillContinueLoading, const UserData&); 125 125 void startURLSchemeTask(URLSchemeTaskParameters&&); 126 void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&& )>&&);126 void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&); 127 127 void decidePolicyForNavigationActionSync(WebCore::FrameIdentifier, bool isMainFrame, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&, 128 128 FrameInfoData&&, Optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody, -
trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp
r254046 r255135 31 31 #include "SessionState.h" 32 32 #include "WebBackForwardCache.h" 33 #include "WebBackForwardListCounts.h" 33 34 #include "WebPageProxy.h" 34 35 #include <WebCore/DiagnosticLoggingClient.h> … … 275 276 } 276 277 278 WebBackForwardListCounts WebBackForwardList::counts() const 279 { 280 return WebBackForwardListCounts { backListCount(), forwardListCount() }; 281 } 282 277 283 Ref<API::Array> WebBackForwardList::backList() const 278 284 { -
trunk/Source/WebKit/UIProcess/WebBackForwardList.h
r239427 r255135 36 36 37 37 struct BackForwardListState; 38 struct WebBackForwardListCounts; 38 39 39 40 class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForwardList> { … … 63 64 unsigned backListCount() const; 64 65 unsigned forwardListCount() const; 66 WebBackForwardListCounts counts() const; 65 67 66 68 Ref<API::Array> backList() const; -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r254886 r255135 97 97 #include "WebBackForwardCache.h" 98 98 #include "WebBackForwardList.h" 99 #include "WebBackForwardListCounts.h" 99 100 #include "WebBackForwardListItem.h" 100 101 #include "WebCertificateInfo.h" … … 6042 6043 } 6043 6044 6044 void WebPageProxy::backForwardGoToItem(const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&& )>&& completionHandler)6045 void WebPageProxy::backForwardGoToItem(const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler) 6045 6046 { 6046 6047 // On process swap, we tell the previous process to ignore the load, which causes it so restore its current back forward item to its previous … … 6048 6049 // Any real new load in the committed process would have cleared m_provisionalPage. 6049 6050 if (m_provisionalPage) 6050 return completionHandler({ } );6051 return completionHandler({ }, m_backForwardList->counts()); 6051 6052 6052 6053 SandboxExtension::Handle sandboxExtensionHandle; … … 6054 6055 } 6055 6056 6056 void WebPageProxy::backForwardGoToItemShared(Ref<WebProcessProxy>&& process, const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&& )>&& completionHandler)6057 void WebPageProxy::backForwardGoToItemShared(Ref<WebProcessProxy>&& process, const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler) 6057 6058 { 6058 6059 auto* item = m_backForwardList->itemForID(itemID); 6059 6060 if (!item) 6060 return completionHandler({ } );6061 return completionHandler({ }, m_backForwardList->counts()); 6061 6062 6062 6063 SandboxExtension::Handle sandboxExtensionHandle; 6063 6064 maybeInitializeSandboxExtensionHandle(process, URL(URL(), item->url()), item->resourceDirectoryURL(), sandboxExtensionHandle); 6064 6065 m_backForwardList->goToItem(*item); 6065 completionHandler(WTFMove(sandboxExtensionHandle) );6066 completionHandler(WTFMove(sandboxExtensionHandle), m_backForwardList->counts()); 6066 6067 } 6067 6068 … … 6074 6075 } 6075 6076 6076 void WebPageProxy::backForwardBackListCount(CompletionHandler<void(uint32_t)>&& completionHandler) 6077 { 6078 completionHandler(m_backForwardList->backListCount()); 6079 } 6080 6081 void WebPageProxy::backForwardForwardListCount(CompletionHandler<void(uint32_t)>&& completionHandler) 6082 { 6083 completionHandler(m_backForwardList->forwardListCount()); 6077 void WebPageProxy::backForwardListCounts(Messages::WebPageProxy::BackForwardListCountsDelayedReply&& completionHandler) 6078 { 6079 completionHandler(m_backForwardList->counts()); 6084 6080 } 6085 6081 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r255054 r255135 309 309 310 310 struct AttributedString; 311 struct WebBackForwardListCounts; 311 312 struct ColorSpaceData; 312 313 struct DataDetectionResult; … … 1596 1597 void loadDataWithNavigationShared(Ref<WebProcessProxy>&&, WebCore::PageIdentifier, API::Navigation&, const IPC::DataReference&, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData, WebCore::ShouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&& = WTF::nullopt, WebCore::ShouldOpenExternalURLsPolicy = WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow); 1597 1598 void loadRequestWithNavigationShared(Ref<WebProcessProxy>&&, WebCore::PageIdentifier, API::Navigation&, WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy, API::Object* userData, WebCore::ShouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&& = WTF::nullopt); 1598 void backForwardGoToItemShared(Ref<WebProcessProxy>&&, const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&& )>&&);1599 void backForwardGoToItemShared(Ref<WebProcessProxy>&&, const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&); 1599 1600 void decidePolicyForNavigationActionSyncShared(Ref<WebProcessProxy>&&, WebCore::FrameIdentifier, bool isMainFrame, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&, 1600 1601 FrameInfoData&&, Optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody, … … 1894 1895 // Back/Forward list management 1895 1896 void backForwardAddItem(BackForwardListItemState&&); 1896 void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&& )>&&);1897 void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&); 1897 1898 void backForwardItemAtIndex(int32_t index, CompletionHandler<void(Optional<WebCore::BackForwardItemIdentifier>&&)>&&); 1898 void backForwardBackListCount(CompletionHandler<void(uint32_t)>&&); 1899 void backForwardForwardListCount(CompletionHandler<void(uint32_t)>&&); 1899 void backForwardListCounts(Messages::WebPageProxy::BackForwardListCountsDelayedReply&&); 1900 1900 void backForwardClear(); 1901 1901 -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r254312 r255135 225 225 # BackForward messages 226 226 BackForwardAddItem(struct WebKit::BackForwardListItemState itemState) 227 BackForwardGoToItem(struct WebCore::BackForwardItemIdentifier itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle ) Synchronous227 BackForwardGoToItem(struct WebCore::BackForwardItemIdentifier itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle, struct WebKit::WebBackForwardListCounts counts) Synchronous 228 228 BackForwardItemAtIndex(int32_t itemIndex) -> (Optional<WebCore::BackForwardItemIdentifier> itemID) Synchronous 229 BackForwardBackListCount() -> (uint32_t count) Synchronous 230 BackForwardForwardListCount() -> (uint32_t count) Synchronous 229 BackForwardListCounts() -> (struct WebKit::WebBackForwardListCounts counts) Synchronous 231 230 BackForwardClear() 232 231 WillGoToBackForwardListItem(struct WebCore::BackForwardItemIdentifier itemID, bool inBackForwardCache) -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r254931 r255135 951 951 46BEB6E322FBB21A00269867 /* TransientLocalStorageNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 46BEB6E122FBB21A00269867 /* TransientLocalStorageNamespace.h */; }; 952 952 46C392292316EC4D008EED9B /* WebPageProxyIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C392282316EC4D008EED9B /* WebPageProxyIdentifier.h */; }; 953 46CE3B1123D8C8490016A96A /* WebBackForwardListCounts.h in Headers */ = {isa = PBXBuildFile; fileRef = 46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */; }; 953 954 46DF063C1F3905F8001980BB /* NetworkCORSPreflightChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */; }; 954 955 46F77D8023BE63BE0090B5A7 /* DependencyProcessAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = 46F77D7E23BE63B10090B5A7 /* DependencyProcessAssertion.h */; }; … … 3490 3491 46BEB6E222FBB21A00269867 /* TransientLocalStorageNamespace.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TransientLocalStorageNamespace.cpp; sourceTree = "<group>"; }; 3491 3492 46C392282316EC4D008EED9B /* WebPageProxyIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPageProxyIdentifier.h; sourceTree = "<group>"; }; 3493 46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBackForwardListCounts.h; sourceTree = "<group>"; }; 3492 3494 46DF06391F3905E5001980BB /* NetworkCORSPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCORSPreflightChecker.cpp; sourceTree = "<group>"; }; 3493 3495 46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCORSPreflightChecker.h; sourceTree = "<group>"; }; … … 5759 5761 2684054A18B866FF0022C38B /* VisibleContentRectUpdateInfo.cpp */, 5760 5762 2684054218B85A630022C38B /* VisibleContentRectUpdateInfo.h */, 5763 46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */, 5761 5764 518D2CAB12D5153B003BB93B /* WebBackForwardListItem.cpp */, 5762 5765 518D2CAC12D5153B003BB93B /* WebBackForwardListItem.h */, … … 10568 10571 46F9B26323526EF3006FE5FA /* WebBackForwardCacheEntry.h in Headers */, 10569 10572 BC72BA1E11E64907001EB4EA /* WebBackForwardList.h in Headers */, 10573 46CE3B1123D8C8490016A96A /* WebBackForwardListCounts.h in Headers */, 10570 10574 518D2CAE12D5153B003BB93B /* WebBackForwardListItem.h in Headers */, 10571 10575 BC72B9FB11E6476B001EB4EA /* WebBackForwardListProxy.h in Headers */, -
trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp
r251220 r255135 61 61 ASSERT_UNUSED(overwriteExistingItem, overwriteExistingItem == OverwriteExistingItem::Yes || !idToHistoryItemMap().contains(itemID)); 62 62 idToHistoryItemMap().set(itemID, item.ptr()); 63 clearCachedListCounts(); 63 64 } 64 65 … … 98 99 99 100 LOG(BackForward, "(Back/Forward) WebProcess pid %i setting item %p for id %s with url %s", getCurrentProcessID(), item.ptr(), item->identifier().logString(), item->urlString().utf8().data()); 101 clearCachedListCounts(); 100 102 m_page->send(Messages::WebPageProxy::BackForwardAddItem(toBackForwardListItemState(item.get()))); 101 103 } … … 107 109 108 110 SandboxExtension::Handle sandboxExtensionHandle; 109 m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(item.identifier()), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle)); 111 WebBackForwardListCounts backForwardListCounts; 112 m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(item.identifier()), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle, backForwardListCounts)); 113 m_cachedBackForwardListCounts = backForwardListCounts; 110 114 m_page->sandboxExtensionTracker().beginLoad(m_page->mainWebFrame(), WTFMove(sandboxExtensionHandle)); 111 115 } … … 128 132 unsigned WebBackForwardListProxy::backListCount() const 129 133 { 130 if (!m_page) 131 return 0; 132 133 unsigned backListCount = 0; 134 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardBackListCount(), Messages::WebPageProxy::BackForwardBackListCount::Reply(backListCount), m_page->identifier())) 135 return 0; 136 137 return backListCount; 134 return cacheListCountsIfNecessary().backCount; 138 135 } 139 136 140 137 unsigned WebBackForwardListProxy::forwardListCount() const 141 138 { 142 if (!m_page)143 return 0; 139 return cacheListCountsIfNecessary().forwardCount; 140 } 144 141 145 unsigned forwardListCount = 0; 146 if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardForwardListCount(), Messages::WebPageProxy::BackForwardForwardListCount::Reply(forwardListCount), m_page->identifier())) 147 return 0; 142 const WebBackForwardListCounts& WebBackForwardListProxy::cacheListCountsIfNecessary() const 143 { 144 if (!m_cachedBackForwardListCounts) { 145 WebBackForwardListCounts backForwardListCounts; 146 if (m_page) 147 WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardListCounts(), Messages::WebPageProxy::BackForwardListCounts::Reply(backForwardListCounts), m_page->identifier()); 148 m_cachedBackForwardListCounts = backForwardListCounts; 149 } 150 return *m_cachedBackForwardListCounts; 151 } 148 152 149 return forwardListCount; 153 void WebBackForwardListProxy::clearCachedListCounts() 154 { 155 m_cachedBackForwardListCounts = WTF::nullopt; 150 156 } 151 157 … … 154 160 ASSERT(m_page); 155 161 m_page = nullptr; 162 m_cachedBackForwardListCounts = WebBackForwardListCounts { }; 156 163 } 157 164 158 165 void WebBackForwardListProxy::clear() 159 166 { 167 m_cachedBackForwardListCounts = WebBackForwardListCounts { }; // Clearing the back/forward list will cause the counts to become 0. 160 168 m_page->send(Messages::WebPageProxy::BackForwardClear()); 161 169 } -
trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h
r245796 r255135 26 26 #pragma once 27 27 28 #include "WebBackForwardListCounts.h" 28 29 #include <WebCore/BackForwardClient.h> 29 30 #include <WebCore/PageIdentifier.h> … … 63 64 unsigned backListCount() const override; 64 65 unsigned forwardListCount() const override; 66 const WebBackForwardListCounts& cacheListCountsIfNecessary() const; 67 void clearCachedListCounts(); 65 68 66 69 void close() override; 67 70 68 71 WebPage* m_page; 72 mutable Optional<WebBackForwardListCounts> m_cachedBackForwardListCounts; 69 73 }; 70 74
Note: See TracChangeset
for help on using the changeset viewer.