Bug 244724 - AX: Cache accessibilityIsIgnored before in AXIsolatedTree::generateSubtree and AXIsolatedTree::updateChildren
Summary: AX: Cache accessibilityIsIgnored before in AXIsolatedTree::generateSubtree an...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tyler Wilcock
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-09-02 13:16 PDT by Tyler Wilcock
Modified: 2023-05-25 10:28 PDT (History)
10 users (show)

See Also:


Attachments
Patch (4.41 KB, patch)
2022-09-02 13:23 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (4.56 KB, patch)
2023-05-23 17:34 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff
Patch (4.53 KB, patch)
2023-05-24 10:36 PDT, Tyler Wilcock
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tyler Wilcock 2022-09-02 13:16:11 PDT
We do a lot of repeated live tree reads in these codepaths, so we should make sure we are caching is-ignored for better performance.
Comment 1 Radar WebKit Bug Importer 2022-09-02 13:16:21 PDT
<rdar://problem/99501850>
Comment 2 Tyler Wilcock 2022-09-02 13:23:50 PDT
Created attachment 462104 [details]
Patch
Comment 3 chris fleizach 2022-09-05 23:12:03 PDT
Comment on attachment 462104 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=462104&action=review

> COMMIT_MESSAGE:12
> +This patch also AXAttributeCacheEnabler to not disable the AXComputedObjectAttributeCache

also modifies(?)

> Source/WebCore/accessibility/AXObjectCache.h:605
> +    bool m_wasAlreadyCachingAttributes { false };

wasAlready feel redundant to just having "m_cachingAttributes"... or maybe something shorter "m_inAttributeCaching"
Comment 4 Andres Gonzalez 2022-09-07 05:59:16 PDT
(In reply to Tyler Wilcock from comment #2)
> Created attachment 462104 [details]
> Patch

--- a/Source/WebCore/accessibility/AXObjectCache.h
+++ a/Source/WebCore/accessibility/AXObjectCache.h

+    bool m_wasAlreadyCachingAttributes { false };

Why do we need this extra flag?

--- a/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
+++ a/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
@@ -205,6 +205,8 @@ void AXIsolatedTree::generateSubtree(AXCoreObject& axObject)
     if (!axObject.objectID().isValid())
         return;

+    // We're about to a lot of read-only work, so start the attribute cache.

"to a lot" -> "to do a lot"

What do you mean by "read-only work"? Not read-only for this isolated tree.

@@ -533,6 +535,9 @@ void AXIsolatedTree::updateChildren(AccessibilityObject& axObject, ResolveNodeCh
     if (!axObject.document() || !axObject.document()->hasLivingRenderTree())
         return;

+    // We're about to a lot of read-only work, so start the attribute cache.

Dito.
Comment 5 Tyler Wilcock 2023-05-23 17:34:36 PDT
Created attachment 466469 [details]
Patch
Comment 6 Tyler Wilcock 2023-05-23 17:38:09 PDT
(In reply to chris fleizach from comment #3)
> Comment on attachment 462104 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=462104&action=review
> 
> > COMMIT_MESSAGE:12
> > +This patch also AXAttributeCacheEnabler to not disable the AXComputedObjectAttributeCache
> 
> also modifies(?)
> 
> > Source/WebCore/accessibility/AXObjectCache.h:605
> > +    bool m_wasAlreadyCachingAttributes { false };
> 
> wasAlready feel redundant to just having "m_cachingAttributes"... or maybe
> something shorter "m_inAttributeCaching"
The intent I'm trying to capture is whether AXObjectCache::computedObjectAttributeCache existed before this AXAttributeCacheEnabler was created (i.e. we were already caching attributes). If so, we need to set this flag so we don't destroy it when this AXAttributeCacheEnabler is destroyed.

I feel like m_inAttributeCaching or m_cachingAttributes don't capture that as well as m_wasAlreadyCachingAttributes...but I don't feel too strongly about it.
Comment 7 Tyler Wilcock 2023-05-23 17:38:50 PDT
(In reply to Andres Gonzalez from comment #4)
> (In reply to Tyler Wilcock from comment #2)
> > Created attachment 462104 [details]
> > Patch
> 
> --- a/Source/WebCore/accessibility/AXObjectCache.h
> +++ a/Source/WebCore/accessibility/AXObjectCache.h
> 
> +    bool m_wasAlreadyCachingAttributes { false };
> 
> Why do we need this extra flag?
I tried to describe this in the commit message, but let me know if that needs some more clarity.
Comment 8 Andres Gonzalez 2023-05-24 08:46:37 PDT
(In reply to Tyler Wilcock from comment #5)
> Created attachment 466469 [details]
> Patch

--- a/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp
+++ b/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp

+    // We're about to a lot of read-only work, so start the attribute cache.

about to a lot -> about to do a lot ?

Is traversing the live tree always read-only? I think there are cases where getting the children for an object, for instance, can change the role of that object.
Comment 9 Andres Gonzalez 2023-05-24 09:00:24 PDT
(In reply to Tyler Wilcock from comment #6)
> (In reply to chris fleizach from comment #3)
> > Comment on attachment 462104 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=462104&action=review
> > 
> > > COMMIT_MESSAGE:12
> > > +This patch also AXAttributeCacheEnabler to not disable the AXComputedObjectAttributeCache
> > 
> > also modifies(?)
> > 
> > > Source/WebCore/accessibility/AXObjectCache.h:605
> > > +    bool m_wasAlreadyCachingAttributes { false };
> > 
> > wasAlready feel redundant to just having "m_cachingAttributes"... or maybe
> > something shorter "m_inAttributeCaching"
> The intent I'm trying to capture is whether
> AXObjectCache::computedObjectAttributeCache existed before this
> AXAttributeCacheEnabler was created (i.e. we were already caching
> attributes). If so, we need to set this flag so we don't destroy it when
> this AXAttributeCacheEnabler is destroyed.
> 
> I feel like m_inAttributeCaching or m_cachingAttributes don't capture that
> as well as m_wasAlreadyCachingAttributes...but I don't feel too strongly
> about it.

Agree that it should be a shorter name. 

Where is this flag turned off? generateSubtree and updateChildren will turn it on but not off, i.e., once it is on, it will be on until something else turns it off. I believe this whole mechanism is quite weak and bug prone.
Comment 10 Tyler Wilcock 2023-05-24 10:36:26 PDT
Created attachment 466483 [details]
Patch
Comment 11 Tyler Wilcock 2023-05-24 10:43:26 PDT
(In reply to Andres Gonzalez from comment #9)
> (In reply to Tyler Wilcock from comment #6)
> > (In reply to chris fleizach from comment #3)
> > > Comment on attachment 462104 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=462104&action=review
> > > 
> > > > COMMIT_MESSAGE:12
> > > > +This patch also AXAttributeCacheEnabler to not disable the AXComputedObjectAttributeCache
> > > 
> > > also modifies(?)
> > > 
> > > > Source/WebCore/accessibility/AXObjectCache.h:605
> > > > +    bool m_wasAlreadyCachingAttributes { false };
> > > 
> > > wasAlready feel redundant to just having "m_cachingAttributes"... or maybe
> > > something shorter "m_inAttributeCaching"
> > The intent I'm trying to capture is whether
> > AXObjectCache::computedObjectAttributeCache existed before this
> > AXAttributeCacheEnabler was created (i.e. we were already caching
> > attributes). If so, we need to set this flag so we don't destroy it when
> > this AXAttributeCacheEnabler is destroyed.
> > 
> > I feel like m_inAttributeCaching or m_cachingAttributes don't capture that
> > as well as m_wasAlreadyCachingAttributes...but I don't feel too strongly
> > about it.
> 
> Agree that it should be a shorter name. 
> 
> Where is this flag turned off? generateSubtree and updateChildren will turn
> it on but not off, i.e., once it is on, it will be on until something else
> turns it off. I believe this whole mechanism is quite weak and bug prone.
Re-capping our conversation off Bugzilla for posterity:

The cache is turned off when the highest-most-stackframe AXAttributeCacheEnabler is destroyed, or when we post any notification. We should be safe from this causing bugs because we unconditionally bust the cache in every known way the tree mutates such that a different is-ignored value would be computed.
Comment 12 Tyler Wilcock 2023-05-24 10:44:12 PDT
Also made the name of the flag shorter.
Comment 13 EWS 2023-05-25 10:28:54 PDT
Committed 264524@main (9128760a1c6a): <https://commits.webkit.org/264524@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 466483 [details].