Skip to content

Commit

Permalink
AX: Initialize the AX thread on first client request.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259952
<rdar://problem/113592230>

Reviewed by Tyler Wilcock.

The AX thread was being initialize after building an empty isolated tree in AXObjectCache::getOrCreateIsolatedTree. However, there are multiple client requests that happen before the AX thread was initialized that come through the WKAccessibilityWebPageObject. If the main thread is busy parsing and rendering the page, those requests may not be served in a long time, causing clients like VoiceOver to report irresponsive application. That's true especially during the loading of large pages. This patch moves the initialization of the AX thread to the first request received in [WKAccessibilityWebPageObject accessibilityAttributeValue:], mitigating main thread contention in this scenario.

* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::getOrCreateIsolatedTree):
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/mac/AXObjectCacheMac.mm:
(WebCore::AXObjectCache::initializeAXThreadIfNeeded):
(WebCore::AXObjectCache::initializeSecondaryAXThread): Renamed.
* Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
(-[WKAccessibilityWebPageObject accessibilityAttributeValue:]):

Canonical link: https://commits.webkit.org/266735@main
  • Loading branch information
AndresGonzalezApple committed Aug 9, 2023
1 parent 25f2b30 commit fbca8d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/accessibility/AXObjectCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ RefPtr<AXIsolatedTree> AXObjectCache::getOrCreateIsolatedTree()
tree = AXIsolatedTree::create(*this);
setIsolatedTreeRoot(tree->rootNode().get());

AXObjectCache::initializeSecondaryAXThread();
initializeAXThreadIfNeeded();

return tree;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/accessibility/AXObjectCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class AXObjectCache : public CanMakeWeakPtr<AXObjectCache>, public CanMakeChecke
void scheduleObjectRegionsUpdate(bool scheduleImmediately = false) { m_geometryManager->scheduleObjectRegionsUpdate(scheduleImmediately); }
void willUpdateObjectRegions() { m_geometryManager->willUpdateObjectRegions(); }
WEBCORE_EXPORT static bool isIsolatedTreeEnabled();
WEBCORE_EXPORT static void initializeAXThreadIfNeeded();
private:
static bool clientSupportsIsolatedTree();
static bool isTestClient();
Expand All @@ -485,7 +486,6 @@ class AXObjectCache : public CanMakeWeakPtr<AXObjectCache>, public CanMakeChecke
void updateIsolatedTree(AccessibilityObject&, AXNotification);
void updateIsolatedTree(AccessibilityObject*, AXNotification);
void updateIsolatedTree(const Vector<std::pair<RefPtr<AccessibilityObject>, AXNotification>>&);
static void initializeSecondaryAXThread();
#endif

protected:
Expand Down
12 changes: 8 additions & 4 deletions Source/WebCore/accessibility/mac/AXObjectCacheMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,16 @@ static bool isTestAXClientType(AXClientType client)
return enabled;
}

void AXObjectCache::initializeSecondaryAXThread()
void AXObjectCache::initializeAXThreadIfNeeded()
{
// Now that we have created our tree, initialize the secondary thread,
// so future requests come in on the other thread.
if (_AXSIsolatedTreeModeFunctionIsAvailable() && _AXSIsolatedTreeMode_Soft() == AXSIsolatedTreeModeSecondaryThread)
static bool axThreadInitialized = false;
if (LIKELY(axThreadInitialized || !isMainThread()))
return;

if (_AXSIsolatedTreeModeFunctionIsAvailable() && _AXSIsolatedTreeMode_Soft() == AXSIsolatedTreeModeSecondaryThread) {
_AXUIElementUseSecondaryAXThread(true);
axThreadInitialized = true;
}
}
#endif // ENABLE(ACCESSIBILITY_ISOLATED_TREE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ - (id)accessibilityAttributeValue:(NSString *)attribute
{
if (!WebCore::AXObjectCache::accessibilityEnabled())
WebCore::AXObjectCache::enableAccessibility();


#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
if (WebCore::AXObjectCache::isIsolatedTreeEnabled())
WebCore::AXObjectCache::initializeAXThreadIfNeeded();
#endif

if ([attribute isEqualToString:NSAccessibilityParentAttribute])
return m_parent.get();

Expand Down

0 comments on commit fbca8d9

Please sign in to comment.