Cache [WKAccessibilityWebPageObject accessibilityParameterizedAttributeNames] to...
authorandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2020 00:41:02 +0000 (00:41 +0000)
committerandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2020 00:41:02 +0000 (00:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=209767

Reviewed by Chris Fleizach.

[WKAccessibilityWebPageObject accessibilityParameterizedAttributeNames]
is called often in isolated tree mode causing a dispatch to the main thread.
This change caches this value so it doesn't keep hitting the main thread.

* WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
(-[WKAccessibilityWebPageObject ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm

index 4fda26b..3f8a247 100644 (file)
@@ -1,3 +1,17 @@
+2020-03-30  Andres Gonzalez  <andresg_22@apple.com>
+
+        Cache [WKAccessibilityWebPageObject accessibilityParameterizedAttributeNames] to avoid hitting often the main thread in isolated tree mode.
+        https://bugs.webkit.org/show_bug.cgi?id=209767
+
+        Reviewed by Chris Fleizach.
+
+        [WKAccessibilityWebPageObject accessibilityParameterizedAttributeNames]
+        is called often in isolated tree mode causing a dispatch to the main thread.
+        This change caches this value so it doesn't keep hitting the main thread.
+
+        * WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
+        (-[WKAccessibilityWebPageObject ALLOW_DEPRECATED_IMPLEMENTATIONS_END]):
+
 2020-03-30  Chris Dumez  <cdumez@apple.com>
 
         WebKit should take a foreground assertion for offscreen loads when the app is foreground
index e8c0bcf..f0ceca2 100644 (file)
 
 namespace ax = WebCore::Accessibility;
 
+@interface WKAccessibilityWebPageObject()
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+@property (nonatomic, strong) NSArray *cachedParameterizedAttributeNames;
+#endif
+@end
+
 @implementation WKAccessibilityWebPageObject
 
 #define PROTECTED_SELF protectedSelf = RetainPtr<WKAccessibilityWebPageObject>(self)
@@ -86,17 +92,28 @@ ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN
 - (NSArray *)accessibilityParameterizedAttributeNames
 ALLOW_DEPRECATED_IMPLEMENTATIONS_END
 {
-    return ax::retrieveValueFromMainThread<RetainPtr<id>>([PROTECTED_SELF] () -> RetainPtr<id> {
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    if (id cachedNames = self.cachedParameterizedAttributeNames)
+        return cachedNames;
+#endif
+
+    id names = ax::retrieveValueFromMainThread<RetainPtr<id>>([PROTECTED_SELF] () -> RetainPtr<id> {
         NSMutableArray *names = [NSMutableArray array];
         if (!protectedSelf->m_page)
             return names;
-        
-        if (auto corePage = protectedSelf->m_page->corePage()) {
+
+        if (auto* corePage = protectedSelf->m_page->corePage()) {
             for (auto& name : corePage->pageOverlayController().copyAccessibilityAttributesNames(true))
                 [names addObject:(NSString *)name];
         }
         return names;
     }).autorelease();
+
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    self.cachedParameterizedAttributeNames = names;
+#endif
+
+    return names;
 }
 
 ALLOW_DEPRECATED_IMPLEMENTATIONS_BEGIN