Make Document::existingAXObjectCache() fast with accessibility disabled.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Oct 2016 19:35:55 +0000 (19:35 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Oct 2016 19:35:55 +0000 (19:35 +0000)
<https://webkit.org/b/163347>

Reviewed by Antti Koivisto.

Instruments says we were spending 2.3% of Dromaeo/dom-modify.html in this function,
traversing ancestors. Track whether we've ever had a cache, and use that knowledge
to return early if possible.

* dom/Document.cpp:
(WebCore::Document::existingAXObjectCache):
(WebCore::Document::axObjectCache):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp

index c0ca796..7c7e82f 100644 (file)
@@ -1,3 +1,18 @@
+2016-10-12  Andreas Kling  <akling@apple.com>
+
+        Make Document::existingAXObjectCache() fast with accessibility disabled.
+        <https://webkit.org/b/163347>
+
+        Reviewed by Antti Koivisto.
+
+        Instruments says we were spending 2.3% of Dromaeo/dom-modify.html in this function,
+        traversing ancestors. Track whether we've ever had a cache, and use that knowledge
+        to return early if possible.
+
+        * dom/Document.cpp:
+        (WebCore::Document::existingAXObjectCache):
+        (WebCore::Document::axObjectCache):
+
 2016-10-12  Jeremy Huddleston Sequoia  <jeremyhu@apple.com>
 
         [SOUP] trunk r207192 fails to compile due to missing std::function being unavailable (missing #include <functional>)
index c0b9bcf..35b9f65 100644 (file)
@@ -2427,8 +2427,13 @@ void Document::clearAXObjectCache()
     m_axObjectCache = nullptr;
 }
 
+static bool hasEverCreatedAnAXObjectCache = false;
+
 AXObjectCache* Document::existingAXObjectCache() const
 {
+    if (!hasEverCreatedAnAXObjectCache)
+        return nullptr;
+
     Document& topDocument = this->topDocument();
     if (!topDocument.hasLivingRenderTree())
         return nullptr;
@@ -2451,8 +2456,10 @@ AXObjectCache* Document::axObjectCache() const
         return nullptr;
 
     ASSERT(&topDocument == this || !m_axObjectCache);
-    if (!topDocument.m_axObjectCache)
+    if (!topDocument.m_axObjectCache) {
         topDocument.m_axObjectCache = std::make_unique<AXObjectCache>(topDocument);
+        hasEverCreatedAnAXObjectCache = true;
+    }
     return topDocument.m_axObjectCache.get();
 }