Performance improvement for ITextRangeProvider::GetEnclosingElement
This change is an optimizaiton for UIAs GetEnclosingElement.
The cost was in calling |LowestCommonAncestor| because it would compute
multiple parent AXPositions until reaching the common anchor. Creating
a parent Text position is expensive because it calls |MaxTextOffset|.
GetEnclosingElement didn't need an AXPosition so to reduce that cost
a new method |LowestCommonAnchor| has been added which returns the
AXNodeType* that we can use to find the relevant AXPlatformNodeDelegate
to do our work on. |LowestCommonAnchor| may also be used to optimize
other similar APIs which don't necessarily need an AXPosition object.
In order to derive the AXTreeID which is necessary to find the correct
AXPlatformNodeDelegate, AXNode::OwnerTree now exposes its AXTreeID.
This way we can know what the AXTreeID is for an AXNode of an
AXNodePosition anchor. This is already easily accessible from the other
position type BrowserAccessibilityPosition, since BrowserAccessibility
has access to the relevant AXTreeData. Now anchors of both position
types can know what the relevant AXTreeID is for creating delegates!
I measured the perf difference with std::chrono::high_resolution_clock
on an unoptimized debug build.
With a document that contains 2 columns of 100 divs each, and a single
leaf text child in each column, and a text range that spans between the
two columns.
Without Patch :
439.006ms
With Patch :
0.1371ms
Bug: 928948
Change-Id: Ic9648ff34c7c7030c299c8484fb188a873e3af92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790066
Commit-Queue: Adam Ettenberger <[email protected]>
Reviewed-by: Dominic Mazzoni <[email protected]>
Reviewed-by: Kurt Catti-Schmidt <[email protected]>
Cr-Commit-Position: refs/heads/master@{#697344}
diff --git a/ui/accessibility/ax_tree.h b/ui/accessibility/ax_tree.h
index 9e048cb..a706758 100644
--- a/ui/accessibility/ax_tree.h
+++ b/ui/accessibility/ax_tree.h
@@ -55,6 +55,10 @@
const AXTreeData& data() const { return data_; }
// AXNode::OwnerTree override.
+ // Returns the globally unique ID of this accessibility tree.
+ AXTreeID GetAXTreeID() const override;
+
+ // AXNode::OwnerTree override.
// Returns the AXNode with the given |id| if it is part of this AXTree.
AXNode* GetFromId(int32_t id) const override;