Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 139e9a6d68c9f8638cee836da5d04690f8a9d323
https://github.com/WebKit/WebKit/commit/139e9a6d68c9f8638cee836da5d04690f8a9d323
Author: Tyler Wilcock <[email protected]>
Date: 2025-05-20 (Tue, 20 May 2025)
Changed paths:
M Source/WebCore/Sources.txt
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
M Source/WebCore/accessibility/AXCoreObject.cpp
M Source/WebCore/accessibility/AXCoreObject.h
M Source/WebCore/accessibility/AXObjectCache.cpp
M Source/WebCore/accessibility/AXObjectCache.h
M Source/WebCore/accessibility/AXSearchManager.cpp
A Source/WebCore/accessibility/AXTreeStore.cpp
M Source/WebCore/accessibility/AXTreeStore.h
M Source/WebCore/accessibility/AccessibilityMenuList.cpp
M Source/WebCore/accessibility/AccessibilityNodeObject.cpp
M Source/WebCore/accessibility/AccessibilityNodeObject.h
M Source/WebCore/accessibility/AccessibilityObject.cpp
M Source/WebCore/accessibility/AccessibilityObject.h
M Source/WebCore/accessibility/AccessibilitySpinButton.cpp
M Source/WebCore/accessibility/atspi/AXObjectCacheAtspi.cpp
M Source/WebCore/accessibility/atspi/AccessibilityObjectAtspi.h
M Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp
M Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h
M Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
M Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h
M Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm
M Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.h
M Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm
M Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
M Source/WebCore/loader/EmptyClients.cpp
M Source/WebCore/loader/EmptyFrameLoaderClient.h
M Source/WebCore/loader/LocalFrameLoaderClient.h
M Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp
M Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.h
M Source/WebKit/WebProcess/WebPage/WebPage.h
M Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.h
M Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.mm
M Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
M Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h
Log Message:
-----------
AX: Make AXCoreObject ref-counting non-threadsafe, improving performance
https://bugs.webkit.org/show_bug.cgi?id=293164
rdar://151499521
Reviewed by Joshua Hoffman.
AXCoreObject ref-counting had to be threadsafe because prior to this commit,
AXIsolatedObjects were built on the
main-thread (incurring numerous refs along the way), and then "transferred" to
the accessibility thread. However, there
were other places we held refs or otherwise manipulated isolated objects on the
main-thread, even after transferring them:
- Attaching them to wrappers
- Returning the root isolated tree node from the
WKAccessibilityWebPageObjectBase
- Some usages of associatedAXObject() and performFunctionOnMainThread (which
is async) implicitly assumed the associated
isolated object would stay alive for the lifetime of associatedAXObject() /
the dispatched function, which can no
longer be relied upon.
With this commit, instead of creating isolated objects on the main-thread, we
instead create the data needed to populate
an isolated object, and send that plain-struct over. Then the accessibility
thread can create the isolated object, and
thus be the only thing that ever refs and derefs these objects, in turn
allowing us to safely make our ref-counting
non-threadsafe.
This required a host of associated changes:
- Rather than storing the isolated tree root node on
WKAccessibilityWebPageObjectBase, we instead store a thread-safe
pointer to the isolated tree. AXIsolatedTree is still threadsafe
ref-counted, so it's OK to use from either thread,
and we can use it to get the root node when we know we're off the
main-thread.
- The AttachWrapper enum is removed. All isolated objects are now
unconditionally attached on the accessibility thread.
- WebAccessibilityObjectWrapperBase::m_isolatedObjectInitialized has become
an atomic bool, as the secondary thread
writes it when attaching an isolated object to a wrapper, and the
main-thread reads it when destroying a main-thread
object to know whether it should call
NSAccessibilityUnregisterUniqueIdForUIElement. This probably should've always
been atomic, as it was possible to attach isolated objects to wrappers off
the main-thread before this commit too.
- Because all wrapper attachments happen off the main-thread now, there's
nothing to kick off the first AXIsolatedTree::applyPendingChanges.
Usually that happens when we get a backing object in the wrapper, and call
updateObjectBackingStore. But until the
first applyPendingChanges, there is no backingObject, so it's a classic
chicken and egg problem. Solve this by adding
AXTreeStore::applyPendingChangesForAllIsolatedTrees, and calling it
whenever a wrapper is missing a backing object,
as it may be there, just waiting to be attached.
This change has huge performance wins. On pages with slow VO-Right navigation
(e.g. http://html.spec.whatwg.org),
ref-counting took up ~40% of the samples, largely because threadsafe
ref-counting is slow. It also means iOS no longer
unnecessarily pays the cost of threadsafe ref-counting that it didn't even use,
since isolated tree mode is not enabled
for that platform.
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
Add AXTreeStore.cpp.
* Source/WebCore/accessibility/AXCoreObject.cpp:
(WebCore::AXCoreObject::headingLevel const):
* Source/WebCore/accessibility/AXCoreObject.h:
(WebCore::AXCoreObject::AXCoreObject):
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::setIsolatedTree):
(WebCore::AXObjectCache::rootObjectForFrame):
(WebCore::AXObjectCache::isolatedTreeRootObject): Deleted.
(WebCore::AXObjectCache::setIsolatedTreeRoot): Deleted.
* Source/WebCore/accessibility/AXObjectCache.h:
* Source/WebCore/accessibility/AXSearchManager.cpp:
(WebCore::appendChildrenToArray):
* Source/WebCore/accessibility/AXTreeStore.h:
* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::headingTagLevel const): Deleted.
* Source/WebCore/accessibility/AccessibilityNodeObject.h:
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::insertChild):
* Source/WebCore/accessibility/AccessibilityObject.h:
(WebCore::AccessibilityObject::scrollView const):
* Source/WebCore/accessibility/atspi/AXObjectCacheAtspi.cpp:
(WebCore::AXObjectCache::platformPerformDeferredCacheUpdate):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::AXIsolatedObject):
(WebCore::AXIsolatedObject::create):
(WebCore::isDefaultValue):
(WebCore::AXIsolatedObject::associatedAXObject const):
(WebCore::AXIsolatedObject::setMathscripts):
(WebCore::AXIsolatedObject::setObjectProperty):
(WebCore::AXIsolatedObject::setObjectVectorProperty):
(WebCore::AXIsolatedObject::setProperty):
(WebCore::AXIsolatedObject::insertText):
(WebCore::AXIsolatedObject::press):
(WebCore::AXIsolatedObject::initializeProperties): Deleted.
(WebCore::AXIsolatedObject::canBeMultilineTextField): Deleted.
(WebCore::AXIsolatedObject::setOptionalProperty): Deleted.
(WebCore::AXIsolatedObject::scrollView const): Deleted.
(WebCore::AXIsolatedObject::headingTagLevel const): Deleted.
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h:
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::AXIsolatedTree):
(WebCore::AXIsolatedTree::createEmptyContent):
(WebCore::AXIsolatedTree::create):
(WebCore::AXIsolatedTree::applyPendingRootNodeLocked):
(WebCore::AXIsolatedTree::storeTree):
(WebCore::AXIsolatedTree::nodeChangeForObject):
(WebCore::AXIsolatedTree::queueChange):
(WebCore::AXIsolatedTree::addUnconnectedNode):
(WebCore::AXIsolatedTree::resolveAppends):
(WebCore::AXIsolatedTree::queueAppendsAndRemovals):
(WebCore::AXIsolatedTree::collectNodeChangesForSubtree):
(WebCore::AXIsolatedTree::updateNode):
(WebCore::AXIsolatedTree::updateChildren):
(WebCore::AXIsolatedTree::setPendingRootNodeID):
(WebCore::AXIsolatedTree::setPendingRootNodeIDLocked):
(WebCore::AXIsolatedTree::willBeDestroyed):
(WebCore::AXIsolatedTree::applyPendingChanges):
(WebCore::AXIsolatedTree::processQueuedNodeUpdates):
(WebCore::convertToPropertyFlag):
(WebCore::setPropertyIn):
(WebCore::shouldCacheElementName):
(WebCore::canBeMultilineTextField):
(WebCore::createIsolatedObjectData):
(WebCore::AXIsolatedTree::applyPendingRootNode): Deleted.
(WebCore::AXIsolatedTree::setPendingRootNodeLocked): Deleted.
* Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h:
(WebCore::IsolatedObjectData::IsolatedObjectData):
(WebCore::IsolatedObjectData::setProperty):
(WebCore::AXIsolatedTree::axObjectCacheID const):
(WebCore::AXIsolatedTree::rootNode):
(WebCore::AXIsolatedTree::NodeChange::NodeChange):
* Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::appendBasePlatformProperties):
(WebCore::appendPlatformProperties):
(WebCore::AXIsolatedObject::initializeBasePlatformProperties): Deleted.
(WebCore::AXIsolatedObject::initializePlatformProperties): Deleted.
* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.h:
* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
(-[WebAccessibilityObjectWrapperBase attachIsolatedObject:]):
(-[WebAccessibilityObjectWrapperBase hasIsolatedObject]):
(-[WebAccessibilityObjectWrapperBase detachIsolatedObject:]):
(-[WebAccessibilityObjectWrapperBase updateObjectBackingStore]):
(-[WebAccessibilityObjectWrapperBase axBackingObject]):
* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(-[WebAccessibilityObjectWrapper _accessibilityShowContextMenu]):
(-[WebAccessibilityObjectWrapper
_accessibilityChildrenFromIndex:maxCount:returnPlatformElements:]):
* Source/WebCore/loader/EmptyClients.cpp:
(WebCore::EmptyFrameLoaderClient::setIsolatedTree):
(WebCore::EmptyFrameLoaderClient::setAXIsolatedTreeRoot): Deleted.
* Source/WebCore/loader/EmptyFrameLoaderClient.h:
* Source/WebCore/loader/LocalFrameLoaderClient.h:
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp:
(WebKit::WebLocalFrameLoaderClient::setIsolatedTree):
(WebKit::WebLocalFrameLoaderClient::setAXIsolatedTreeRoot): Deleted.
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.h:
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.h:
* Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.mm:
(-[WKAccessibilityWebPageObjectBase accessibilityRootObjectWrapper:]):
(-[WKAccessibilityWebPageObjectBase setIsolatedTree:]):
(-[WKAccessibilityWebPageObjectBase setIsolatedTreeRoot:]): Deleted.
* Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::setIsolatedTree):
(WebKit::WebPage::setAXIsolatedTreeRoot): Deleted.
* Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h:
Canonical link: https://commits.webkit.org/295174@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes