Title: [288405] trunk/Source/WebCore
Revision
288405
Author
[email protected]
Date
2022-01-22 10:17:10 -0800 (Sat, 22 Jan 2022)

Log Message

Create ancestry of isolated objects instead of generating the entire subtree for an ancestor.
https://bugs.webkit.org/show_bug.cgi?id=235389
<rdar://problem/87803473>

Reviewed by Chris Fleizach.

AXIsolatedTree::updateChildren may be called for an AXObject that has no
corresponding IsolatedObject. That is the case of empty canvas and some
empty div elements. In those cases we were generating the subtree of the
first available ancestor in the isolated tre. This can be expensive
because in some cases the immediate exisiting ancestor was the webarea,
causing the re-generation of the entire isolated tree. With this patch,
only the IsolatedObjects that are missing in the isolated tree are added
to the tree.

* accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::nodeChangeForObject):
(WebCore::AXIsolatedTree::queueChanges):
The above two methods are added to avoid coude duplication and to be
able to decouple the creation of new isolated objects from the addition
of those objects to the isolated tree.
(WebCore::AXIsolatedTree::createSubtree):
(WebCore::AXIsolatedTree::updateChildren):
* accessibility/isolatedtree/AXIsolatedTree.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288404 => 288405)


--- trunk/Source/WebCore/ChangeLog	2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/ChangeLog	2022-01-22 18:17:10 UTC (rev 288405)
@@ -1,3 +1,30 @@
+2022-01-22  Andres Gonzalez  <[email protected]>
+
+        Create ancestry of isolated objects instead of generating the entire subtree for an ancestor.
+        https://bugs.webkit.org/show_bug.cgi?id=235389
+        <rdar://problem/87803473>
+
+        Reviewed by Chris Fleizach.
+
+        AXIsolatedTree::updateChildren may be called for an AXObject that has no
+        corresponding IsolatedObject. That is the case of empty canvas and some
+        empty div elements. In those cases we were generating the subtree of the
+        first available ancestor in the isolated tre. This can be expensive
+        because in some cases the immediate exisiting ancestor was the webarea,
+        causing the re-generation of the entire isolated tree. With this patch,
+        only the IsolatedObjects that are missing in the isolated tree are added
+        to the tree.
+
+        * accessibility/isolatedtree/AXIsolatedTree.cpp:
+        (WebCore::AXIsolatedTree::nodeChangeForObject):
+        (WebCore::AXIsolatedTree::queueChanges):
+        The above two methods are added to avoid coude duplication and to be
+        able to decouple the creation of new isolated objects from the addition
+        of those objects to the isolated tree.
+        (WebCore::AXIsolatedTree::createSubtree):
+        (WebCore::AXIsolatedTree::updateChildren):
+        * accessibility/isolatedtree/AXIsolatedTree.h:
+
 2022-01-22  Oriol Brufau  <[email protected]>
 
         [CSS Cascade Layers] Enable CSSImportRule.layerName for WebKitGTK

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp (288404 => 288405)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp	2022-01-22 18:17:10 UTC (rev 288405)
@@ -202,25 +202,20 @@
         updateChildrenIDs(axParent->objectID(), axParent->childrenIDs());
 }
 
-Ref<AXIsolatedObject> AXIsolatedTree::createSubtree(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
+AXIsolatedTree::NodeChange AXIsolatedTree::nodeChangeForObject(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
 {
-    AXTRACE("AXIsolatedTree::createSubtree");
     ASSERT(isMainThread());
 
-    if (!m_creatingSubtree)
-        axObjectCache()->processDeferredChildrenChangedList();
-    SetForScope<bool> creatingSubtree(m_creatingSubtree, true);
+    auto object = AXIsolatedObject::create(axObject, this, parentID);
+    NodeChange nodeChange { object, nullptr };
 
-    auto object = AXIsolatedObject::create(axObject, this, parentID);
     if (!object->objectID().isValid()) {
         // Either the axObject has an invalid ID or something else went terribly wrong. Don't bother doing anything else.
         ASSERT_NOT_REACHED();
-        return object;
+        return nodeChange;
     }
 
     ASSERT(axObject.wrapper());
-
-    NodeChange nodeChange { object, nullptr };
     if (attachWrapper)
         object->attachPlatformWrapper(axObject.wrapper());
     else {
@@ -228,6 +223,29 @@
         nodeChange.wrapper = axObject.wrapper();
     }
 
+    return nodeChange;
+}
+
+void AXIsolatedTree::queueChanges(const NodeChange& nodeChange, Vector<AXID>&& childrenIDs)
+{
+    ASSERT(isMainThread());
+
+    Locker locker { m_changeLogLock };
+    m_pendingAppends.append(nodeChange);
+    updateChildrenIDs(nodeChange.isolatedObject->objectID(), WTFMove(childrenIDs));
+}
+
+Ref<AXIsolatedObject> AXIsolatedTree::createSubtree(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
+{
+    AXTRACE("AXIsolatedTree::createSubtree");
+    ASSERT(isMainThread());
+
+    if (!m_creatingSubtree)
+        axObjectCache()->processDeferredChildrenChangedList();
+    SetForScope<bool> creatingSubtree(m_creatingSubtree, true);
+
+    auto nodeChange = nodeChangeForObject(axObject, parentID, attachWrapper);
+
     auto axChildren = axObject.children();
     Vector<AXID> childrenIDs;
     childrenIDs.reserveCapacity(axChildren.size());
@@ -236,13 +254,9 @@
         childrenIDs.uncheckedAppend(child->objectID());
     }
 
-    {
-        Locker locker { m_changeLogLock };
-        m_pendingAppends.append(WTFMove(nodeChange));
-        updateChildrenIDs(object->objectID(), WTFMove(childrenIDs));
-    }
+    queueChanges(nodeChange, WTFMove(childrenIDs));
 
-    return object;
+    return nodeChange.isolatedObject;
 }
 
 void AXIsolatedTree::updateNode(AXCoreObject& axObject)
@@ -322,12 +336,19 @@
     // is added a new child. So find the closest ancestor of axObject that has
     // an associated isolated object and update its children.
     auto iterator = m_nodeMap.end();
-    auto* axAncestor = Accessibility::findAncestor(axObject, true, [&iterator, this] (const AXCoreObject& ancestor) {
+    auto* axAncestor = Accessibility::findAncestor(axObject, true, [&iterator, this] (auto& ancestor) {
         auto it = m_nodeMap.find(ancestor.objectID());
         if (it != m_nodeMap.end()) {
             iterator = it;
             return true;
         }
+
+        // ancestor has no node in the isolated tree, thus add it.
+        auto* axParent = ancestor.parentObject();
+        AXID axParentID = axParent ? axParent->objectID() : AXID();
+        auto nodeChange = nodeChangeForObject(ancestor, axParentID, true);
+        queueChanges(nodeChange, ancestor.childrenIDs());
+
         return false;
     });
     if (!axAncestor || !axAncestor->objectID().isValid() || iterator == m_nodeMap.end()) {
@@ -368,9 +389,6 @@
         // Make the children IDs of the isolated object to be the same as the AXObject's.
         Locker locker { m_changeLogLock };
         updateChildrenIDs(axAncestor->objectID(), WTFMove(axChildrenIDs));
-    } else {
-        // Nothing was updated. As a last resort, update the subtree.
-        updateSubtree(*axAncestor);
     }
 }
 

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h (288404 => 288405)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2022-01-22 18:17:10 UTC (rev 288405)
@@ -386,7 +386,9 @@
     static HashMap<AXIsolatedTreeID, Ref<AXIsolatedTree>>& treeIDCache() WTF_REQUIRES_LOCK(s_cacheLock);
     static HashMap<PageIdentifier, Ref<AXIsolatedTree>>& treePageCache() WTF_REQUIRES_LOCK(s_cacheLock);
 
-    // Call on main thread
+    // Called on main thread.
+    NodeChange nodeChangeForObject(AXCoreObject&, AXID parentID, bool attachWrapper);
+    void queueChanges(const NodeChange&, Vector<AXID>&& childrenIDs);
     Ref<AXIsolatedObject> createSubtree(AXCoreObject&, AXID parentID, bool attachWrapper);
     // Called on main thread to update both m_nodeMap and m_pendingChildrenUpdates.
     void updateChildrenIDs(AXID parentID, Vector<AXID>&& childrenIDs) WTF_REQUIRES_LOCK(m_changeLogLock);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to