Title: [255135] trunk/Source/WebKit
Revision
255135
Author
[email protected]
Date
2020-01-26 20:38:51 -0800 (Sun, 26 Jan 2020)

Log Message

Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com
https://bugs.webkit.org/show_bug.cgi?id=206438

Reviewed by Darin Adler.

Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com. When scrolling on reddit.com,
you frequently see 2 consecutive sync IPCs (WebPageProxy::BackForwardBackListCount then WebPageProxy::BackForwardForwardListCount)
from the WebContent process to the UIProcess. Those are bad for performance. This happens every time the script on the page accesses
history.length, which is unfortunate, since this history length rarely changes.

To address the issue, the following changes were made:
1. Merge BackForwardBackListCount / BackForwardForwardListCount IPCs into a single BackForwardListCounts IPC which returns both
   the back & forward counts, since we often need both (e.g. when accessing history.length) and since gettings those counts is
   very cheap compared to the cost of a sync IPC.
2. Cache those counts in WebBackForwardListProxy and blow away the cached counts whenever the back/forward list changes. In the
   common case (where the back/forward list rarely changes), we now see a single sync IPC instead of many (verified on reddit.com).

No new tests, merely a performance improvement.

* UIProcess/WebPageProxy.cpp:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebPage/WebBackForwardListProxy.cpp:
(WebKit::WebBackForwardListProxy::addItemFromUIProcess):
(WebKit::WebBackForwardListProxy::addItem):
(WebKit::WebBackForwardListProxy::goToItem):
(WebKit::WebBackForwardListProxy::backListCount const):
(WebKit::WebBackForwardListProxy::forwardListCount const):
(WebKit::WebBackForwardListProxy::cacheListCountsIfNecessary const):
(WebKit::WebBackForwardListProxy::clearCachedListCounts):
(WebKit::WebBackForwardListProxy::close):
(WebKit::WebBackForwardListProxy::clear):
* WebProcess/WebPage/WebBackForwardListProxy.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (255134 => 255135)


--- trunk/Source/WebKit/ChangeLog	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/ChangeLog	2020-01-27 04:38:51 UTC (rev 255135)
@@ -1,3 +1,39 @@
+2020-01-26  Chris Dumez  <[email protected]>
+
+        Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com
+        https://bugs.webkit.org/show_bug.cgi?id=206438
+
+        Reviewed by Darin Adler.
+
+        Frequent sync BackForwardBackListCount/BackForwardForwardListCount IPC on reddit.com. When scrolling on reddit.com,
+        you frequently see 2 consecutive sync IPCs (WebPageProxy::BackForwardBackListCount then WebPageProxy::BackForwardForwardListCount)
+        from the WebContent process to the UIProcess. Those are bad for performance. This happens every time the script on the page accesses
+        history.length, which is unfortunate, since this history length rarely changes.
+
+        To address the issue, the following changes were made:
+        1. Merge BackForwardBackListCount / BackForwardForwardListCount IPCs into a single BackForwardListCounts IPC which returns both
+           the back & forward counts, since we often need both (e.g. when accessing history.length) and since gettings those counts is
+           very cheap compared to the cost of a sync IPC.
+        2. Cache those counts in WebBackForwardListProxy and blow away the cached counts whenever the back/forward list changes. In the
+           common case (where the back/forward list rarely changes), we now see a single sync IPC instead of many (verified on reddit.com).
+
+        No new tests, merely a performance improvement.
+
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
+        (WebKit::WebBackForwardListProxy::addItemFromUIProcess):
+        (WebKit::WebBackForwardListProxy::addItem):
+        (WebKit::WebBackForwardListProxy::goToItem):
+        (WebKit::WebBackForwardListProxy::backListCount const):
+        (WebKit::WebBackForwardListProxy::forwardListCount const):
+        (WebKit::WebBackForwardListProxy::cacheListCountsIfNecessary const):
+        (WebKit::WebBackForwardListProxy::clearCachedListCounts):
+        (WebKit::WebBackForwardListProxy::close):
+        (WebKit::WebBackForwardListProxy::clear):
+        * WebProcess/WebPage/WebBackForwardListProxy.h:
+
 2020-01-26  youenn fablet  <[email protected]>
 
         Use ObjectIdentifier for remote RealtimeMediaSource

Copied: trunk/Source/WebKit/Shared/WebBackForwardListCounts.h (from rev 255134, trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h) (0 => 255135)


--- trunk/Source/WebKit/Shared/WebBackForwardListCounts.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/WebBackForwardListCounts.h	2020-01-27 04:38:51 UTC (rev 255135)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Decoder.h"
+#include "Encoder.h"
+#include <wtf/Optional.h>
+
+namespace WebKit {
+
+struct WebBackForwardListCounts {
+    uint32_t backCount { 0 };
+    uint32_t forwardCount { 0 };
+
+    void encode(IPC::Encoder& encoder) const
+    {
+        encoder << backCount;
+        encoder << forwardCount;
+    }
+
+    static Optional<WebBackForwardListCounts> decode(IPC::Decoder& decoder)
+    {
+        Optional<uint32_t> backCount;
+        decoder >> backCount;
+        if (!backCount)
+            return WTF::nullopt;
+
+        Optional<uint32_t> forwardCount;
+        decoder >> forwardCount;
+        if (!forwardCount)
+            return WTF::nullopt;
+
+        return WebBackForwardListCounts { *backCount, *forwardCount };
+    }
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp	2020-01-27 04:38:51 UTC (rev 255135)
@@ -334,7 +334,7 @@
     m_page.startURLSchemeTaskShared(m_process.copyRef(), m_webPageID, WTFMove(parameters));
 }
 
-void ProvisionalPageProxy::backForwardGoToItem(const WebCore::BackForwardItemIdentifier& identifier, CompletionHandler<void(SandboxExtension::Handle&&)>&& completionHandler)
+void ProvisionalPageProxy::backForwardGoToItem(const WebCore::BackForwardItemIdentifier& identifier, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler)
 {
     m_page.backForwardGoToItemShared(m_process.copyRef(), identifier, WTFMove(completionHandler));
 }

Modified: trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h	2020-01-27 04:38:51 UTC (rev 255135)
@@ -123,7 +123,7 @@
     void didCommitLoadForFrame(WebCore::FrameIdentifier, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, uint32_t frameLoadType, const WebCore::CertificateInfo&, bool containsPluginDocument, Optional<WebCore::HasInsecureContent> forcedHasInsecureContent, const UserData&);
     void didFailProvisionalLoadForFrame(WebCore::FrameIdentifier, WebCore::SecurityOriginData&& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, WebCore::WillContinueLoading, const UserData&);
     void startURLSchemeTask(URLSchemeTaskParameters&&);
-    void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&)>&&);
+    void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&);
     void decidePolicyForNavigationActionSync(WebCore::FrameIdentifier, bool isMainFrame, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&,
         FrameInfoData&&, Optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody,
         WebCore::ResourceResponse&& redirectResponse, const UserData&, Messages::WebPageProxy::DecidePolicyForNavigationActionSyncDelayedReply&&);

Modified: trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/WebBackForwardList.cpp	2020-01-27 04:38:51 UTC (rev 255135)
@@ -30,6 +30,7 @@
 #include "Logging.h"
 #include "SessionState.h"
 #include "WebBackForwardCache.h"
+#include "WebBackForwardListCounts.h"
 #include "WebPageProxy.h"
 #include <WebCore/DiagnosticLoggingClient.h>
 #include <WebCore/DiagnosticLoggingKeys.h>
@@ -274,6 +275,11 @@
     return m_page && m_currentIndex ? m_entries.size() - (*m_currentIndex + 1) : 0;
 }
 
+WebBackForwardListCounts WebBackForwardList::counts() const
+{
+    return WebBackForwardListCounts { backListCount(), forwardListCount() };
+}
+
 Ref<API::Array> WebBackForwardList::backList() const
 {
     return backListAsAPIArrayWithLimit(backListCount());

Modified: trunk/Source/WebKit/UIProcess/WebBackForwardList.h (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/WebBackForwardList.h	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/WebBackForwardList.h	2020-01-27 04:38:51 UTC (rev 255135)
@@ -35,6 +35,7 @@
 namespace WebKit {
 
 struct BackForwardListState;
+struct WebBackForwardListCounts;
 
 class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForwardList> {
 public:
@@ -62,6 +63,7 @@
 
     unsigned backListCount() const;
     unsigned forwardListCount() const;
+    WebBackForwardListCounts counts() const;
 
     Ref<API::Array> backList() const;
     Ref<API::Array> forwardList() const;

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-01-27 04:38:51 UTC (rev 255135)
@@ -96,6 +96,7 @@
 #include "WebAutomationSession.h"
 #include "WebBackForwardCache.h"
 #include "WebBackForwardList.h"
+#include "WebBackForwardListCounts.h"
 #include "WebBackForwardListItem.h"
 #include "WebCertificateInfo.h"
 #include "WebContextMenuItem.h"
@@ -6041,28 +6042,28 @@
     m_backForwardList->addItem(WTFMove(item));
 }
 
-void WebPageProxy::backForwardGoToItem(const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&)>&& completionHandler)
+void WebPageProxy::backForwardGoToItem(const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler)
 {
     // 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
     // value. Since the load is really going on in a new provisional process, we want to ignore such requests from the committed process.
     // Any real new load in the committed process would have cleared m_provisionalPage.
     if (m_provisionalPage)
-        return completionHandler({ });
+        return completionHandler({ }, m_backForwardList->counts());
 
     SandboxExtension::Handle sandboxExtensionHandle;
     backForwardGoToItemShared(m_process.copyRef(), itemID, WTFMove(completionHandler));
 }
 
-void WebPageProxy::backForwardGoToItemShared(Ref<WebProcessProxy>&& process, const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&)>&& completionHandler)
+void WebPageProxy::backForwardGoToItemShared(Ref<WebProcessProxy>&& process, const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&& completionHandler)
 {
     auto* item = m_backForwardList->itemForID(itemID);
     if (!item)
-        return completionHandler({ });
+        return completionHandler({ }, m_backForwardList->counts());
 
     SandboxExtension::Handle sandboxExtensionHandle;
     maybeInitializeSandboxExtensionHandle(process, URL(URL(), item->url()), item->resourceDirectoryURL(),  sandboxExtensionHandle);
     m_backForwardList->goToItem(*item);
-    completionHandler(WTFMove(sandboxExtensionHandle));
+    completionHandler(WTFMove(sandboxExtensionHandle), m_backForwardList->counts());
 }
 
 void WebPageProxy::backForwardItemAtIndex(int32_t index, CompletionHandler<void(Optional<BackForwardItemIdentifier>&&)>&& completionHandler)
@@ -6073,16 +6074,11 @@
         completionHandler(WTF::nullopt);
 }
 
-void WebPageProxy::backForwardBackListCount(CompletionHandler<void(uint32_t)>&& completionHandler)
+void WebPageProxy::backForwardListCounts(Messages::WebPageProxy::BackForwardListCountsDelayedReply&& completionHandler)
 {
-    completionHandler(m_backForwardList->backListCount());
+    completionHandler(m_backForwardList->counts());
 }
 
-void WebPageProxy::backForwardForwardListCount(CompletionHandler<void(uint32_t)>&& completionHandler)
-{
-    completionHandler(m_backForwardList->forwardListCount());
-}
-
 void WebPageProxy::compositionWasCanceled()
 {
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-01-27 04:38:51 UTC (rev 255135)
@@ -308,6 +308,7 @@
 class WebViewDidMoveToWindowObserver;
 
 struct AttributedString;
+struct WebBackForwardListCounts;
 struct ColorSpaceData;
 struct DataDetectionResult;
 struct DocumentEditingContext;
@@ -1595,7 +1596,7 @@
     void startURLSchemeTaskShared(Ref<WebProcessProxy>&&, WebCore::PageIdentifier, URLSchemeTaskParameters&&);
     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);
     void loadRequestWithNavigationShared(Ref<WebProcessProxy>&&, WebCore::PageIdentifier, API::Navigation&, WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy, API::Object* userData, WebCore::ShouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&& = WTF::nullopt);
-    void backForwardGoToItemShared(Ref<WebProcessProxy>&&, const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&)>&&);
+    void backForwardGoToItemShared(Ref<WebProcessProxy>&&, const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&);
     void decidePolicyForNavigationActionSyncShared(Ref<WebProcessProxy>&&, WebCore::FrameIdentifier, bool isMainFrame, WebCore::SecurityOriginData&&, WebCore::PolicyCheckIdentifier, uint64_t navigationID, NavigationActionData&&,
         FrameInfoData&&, Optional<WebPageProxyIdentifier> originatingPageID, const WebCore::ResourceRequest& originalRequest, WebCore::ResourceRequest&&, IPC::FormDataReference&& requestBody,
         WebCore::ResourceResponse&& redirectResponse, const UserData&, Messages::WebPageProxy::DecidePolicyForNavigationActionSyncDelayedReply&&);
@@ -1893,10 +1894,9 @@
 
     // Back/Forward list management
     void backForwardAddItem(BackForwardListItemState&&);
-    void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&)>&&);
+    void backForwardGoToItem(const WebCore::BackForwardItemIdentifier&, CompletionHandler<void(SandboxExtension::Handle&&, const WebBackForwardListCounts&)>&&);
     void backForwardItemAtIndex(int32_t index, CompletionHandler<void(Optional<WebCore::BackForwardItemIdentifier>&&)>&&);
-    void backForwardBackListCount(CompletionHandler<void(uint32_t)>&&);
-    void backForwardForwardListCount(CompletionHandler<void(uint32_t)>&&);
+    void backForwardListCounts(Messages::WebPageProxy::BackForwardListCountsDelayedReply&&);
     void backForwardClear();
 
     // Undo management

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (255134 => 255135)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2020-01-27 04:38:51 UTC (rev 255135)
@@ -224,10 +224,9 @@
 
     # BackForward messages
     BackForwardAddItem(struct WebKit::BackForwardListItemState itemState)
-    BackForwardGoToItem(struct WebCore::BackForwardItemIdentifier itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle) Synchronous
+    BackForwardGoToItem(struct WebCore::BackForwardItemIdentifier itemID) -> (WebKit::SandboxExtension::Handle sandboxExtensionHandle, struct WebKit::WebBackForwardListCounts counts) Synchronous
     BackForwardItemAtIndex(int32_t itemIndex) -> (Optional<WebCore::BackForwardItemIdentifier> itemID) Synchronous
-    BackForwardBackListCount() -> (uint32_t count) Synchronous
-    BackForwardForwardListCount() -> (uint32_t count) Synchronous
+    BackForwardListCounts() -> (struct WebKit::WebBackForwardListCounts counts) Synchronous
     BackForwardClear()
     WillGoToBackForwardListItem(struct WebCore::BackForwardItemIdentifier itemID, bool inBackForwardCache)
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (255134 => 255135)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-01-27 04:38:51 UTC (rev 255135)
@@ -950,6 +950,7 @@
 		46BEB6DF22FBB16B00269867 /* SessionStorageNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 46BEB6DD22FBB16B00269867 /* SessionStorageNamespace.h */; };
 		46BEB6E322FBB21A00269867 /* TransientLocalStorageNamespace.h in Headers */ = {isa = PBXBuildFile; fileRef = 46BEB6E122FBB21A00269867 /* TransientLocalStorageNamespace.h */; };
 		46C392292316EC4D008EED9B /* WebPageProxyIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C392282316EC4D008EED9B /* WebPageProxyIdentifier.h */; };
+		46CE3B1123D8C8490016A96A /* WebBackForwardListCounts.h in Headers */ = {isa = PBXBuildFile; fileRef = 46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */; };
 		46DF063C1F3905F8001980BB /* NetworkCORSPreflightChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */; };
 		46F77D8023BE63BE0090B5A7 /* DependencyProcessAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = 46F77D7E23BE63B10090B5A7 /* DependencyProcessAssertion.h */; };
 		46F9B26323526EF3006FE5FA /* WebBackForwardCacheEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 46F9B26223526ED0006FE5FA /* WebBackForwardCacheEntry.h */; };
@@ -3489,6 +3490,7 @@
 		46BEB6E122FBB21A00269867 /* TransientLocalStorageNamespace.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TransientLocalStorageNamespace.h; sourceTree = "<group>"; };
 		46BEB6E222FBB21A00269867 /* TransientLocalStorageNamespace.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TransientLocalStorageNamespace.cpp; sourceTree = "<group>"; };
 		46C392282316EC4D008EED9B /* WebPageProxyIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPageProxyIdentifier.h; sourceTree = "<group>"; };
+		46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBackForwardListCounts.h; sourceTree = "<group>"; };
 		46DF06391F3905E5001980BB /* NetworkCORSPreflightChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCORSPreflightChecker.cpp; sourceTree = "<group>"; };
 		46DF063A1F3905E5001980BB /* NetworkCORSPreflightChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCORSPreflightChecker.h; sourceTree = "<group>"; };
 		46F77D7E23BE63B10090B5A7 /* DependencyProcessAssertion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DependencyProcessAssertion.h; sourceTree = "<group>"; };
@@ -5758,6 +5760,7 @@
 				1AC1336618565B5700F3EC05 /* UserData.h */,
 				2684054A18B866FF0022C38B /* VisibleContentRectUpdateInfo.cpp */,
 				2684054218B85A630022C38B /* VisibleContentRectUpdateInfo.h */,
+				46CE3B1023D8C83D0016A96A /* WebBackForwardListCounts.h */,
 				518D2CAB12D5153B003BB93B /* WebBackForwardListItem.cpp */,
 				518D2CAC12D5153B003BB93B /* WebBackForwardListItem.h */,
 				BCF50726124329AA005955AE /* WebCertificateInfo.h */,
@@ -10567,6 +10570,7 @@
 				1C0A195C1C916E1B00FE0EBB /* WebAutomationSessionProxyScriptSource.h in Headers */,
 				46F9B26323526EF3006FE5FA /* WebBackForwardCacheEntry.h in Headers */,
 				BC72BA1E11E64907001EB4EA /* WebBackForwardList.h in Headers */,
+				46CE3B1123D8C8490016A96A /* WebBackForwardListCounts.h in Headers */,
 				518D2CAE12D5153B003BB93B /* WebBackForwardListItem.h in Headers */,
 				BC72B9FB11E6476B001EB4EA /* WebBackForwardListProxy.h in Headers */,
 				41897ED11F415D680016FA42 /* WebCacheStorageConnection.h in Headers */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp (255134 => 255135)


--- trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.cpp	2020-01-27 04:38:51 UTC (rev 255135)
@@ -60,6 +60,7 @@
     // This item/itemID pair should not already exist in our map.
     ASSERT_UNUSED(overwriteExistingItem, overwriteExistingItem == OverwriteExistingItem::Yes || !idToHistoryItemMap().contains(itemID));
     idToHistoryItemMap().set(itemID, item.ptr());
+    clearCachedListCounts();
 }
 
 static void WK2NotifyHistoryItemChanged(HistoryItem& item)
@@ -97,6 +98,7 @@
     ASSERT_UNUSED(result, result.isNewEntry);
 
     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());
+    clearCachedListCounts();
     m_page->send(Messages::WebPageProxy::BackForwardAddItem(toBackForwardListItemState(item.get())));
 }
 
@@ -106,7 +108,9 @@
         return;
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(item.identifier()), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle));
+    WebBackForwardListCounts backForwardListCounts;
+    m_page->sendSync(Messages::WebPageProxy::BackForwardGoToItem(item.identifier()), Messages::WebPageProxy::BackForwardGoToItem::Reply(sandboxExtensionHandle, backForwardListCounts));
+    m_cachedBackForwardListCounts = backForwardListCounts;
     m_page->sandboxExtensionTracker().beginLoad(m_page->mainWebFrame(), WTFMove(sandboxExtensionHandle));
 }
 
@@ -127,26 +131,28 @@
 
 unsigned WebBackForwardListProxy::backListCount() const
 {
-    if (!m_page)
-        return 0;
-
-    unsigned backListCount = 0;
-    if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardBackListCount(), Messages::WebPageProxy::BackForwardBackListCount::Reply(backListCount), m_page->identifier()))
-        return 0;
-
-    return backListCount;
+    return cacheListCountsIfNecessary().backCount;
 }
 
 unsigned WebBackForwardListProxy::forwardListCount() const
 {
-    if (!m_page)
-        return 0;
+    return cacheListCountsIfNecessary().forwardCount;
+}
 
-    unsigned forwardListCount = 0;
-    if (!WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardForwardListCount(), Messages::WebPageProxy::BackForwardForwardListCount::Reply(forwardListCount), m_page->identifier()))
-        return 0;
+const WebBackForwardListCounts& WebBackForwardListProxy::cacheListCountsIfNecessary() const
+{
+    if (!m_cachedBackForwardListCounts) {
+        WebBackForwardListCounts backForwardListCounts;
+        if (m_page)
+            WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPageProxy::BackForwardListCounts(), Messages::WebPageProxy::BackForwardListCounts::Reply(backForwardListCounts), m_page->identifier());
+        m_cachedBackForwardListCounts = backForwardListCounts;
+    }
+    return *m_cachedBackForwardListCounts;
+}
 
-    return forwardListCount;
+void WebBackForwardListProxy::clearCachedListCounts()
+{
+    m_cachedBackForwardListCounts = WTF::nullopt;
 }
 
 void WebBackForwardListProxy::close()
@@ -153,10 +159,12 @@
 {
     ASSERT(m_page);
     m_page = nullptr;
+    m_cachedBackForwardListCounts = WebBackForwardListCounts { };
 }
 
 void WebBackForwardListProxy::clear()
 {
+    m_cachedBackForwardListCounts = WebBackForwardListCounts { }; // Clearing the back/forward list will cause the counts to become 0.
     m_page->send(Messages::WebPageProxy::BackForwardClear());
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h (255134 => 255135)


--- trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h	2020-01-26 23:28:44 UTC (rev 255134)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebBackForwardListProxy.h	2020-01-27 04:38:51 UTC (rev 255135)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "WebBackForwardListCounts.h"
 #include <WebCore/BackForwardClient.h>
 #include <WebCore/PageIdentifier.h>
 #include <wtf/HashSet.h>
@@ -62,10 +63,13 @@
     RefPtr<WebCore::HistoryItem> itemAtIndex(int) override;
     unsigned backListCount() const override;
     unsigned forwardListCount() const override;
+    const WebBackForwardListCounts& cacheListCountsIfNecessary() const;
+    void clearCachedListCounts();
 
     void close() override;
 
     WebPage* m_page;
+    mutable Optional<WebBackForwardListCounts> m_cachedBackForwardListCounts;
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to