Bug 249873

Summary: AX: Pre-size AXIsolatedObject::m_propertyMap to avoid unnecessary HashTable reallocations
Product: WebKit Reporter: Tyler Wilcock <tyler_w>
Component: AccessibilityAssignee: Tyler Wilcock <tyler_w>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andresg_22, apinheiro, cfleizach, dmazzoni, ews-watchlist, jcraig, jdiggs, samuel_white, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Tyler Wilcock 2022-12-24 11:37:49 PST
AX: Pre-size AXIsolatedObject::m_propertyMap to avoid unnecessary HashTable reallocations
Comment 1 Radar WebKit Bug Importer 2022-12-24 11:37:59 PST
<rdar://problem/103687278>
Comment 2 Tyler Wilcock 2022-12-24 11:42:38 PST
Created attachment 464196 [details]
Patch
Comment 3 chris fleizach 2022-12-24 11:48:50 PST
Comment on attachment 464196 [details]
Patch

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

> Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:57
> +    m_propertyMap.reserveInitialCapacity(126);

Is there a way to calculate this number less manually
Comment 4 Tyler Wilcock 2022-12-24 11:56:27 PST
(In reply to chris fleizach from comment #3)
> Comment on attachment 464196 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=464196&action=review
> 
> > Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:57
> > +    m_propertyMap.reserveInitialCapacity(126);
> 
> Is there a way to calculate this number less manually
I don't think so. We could do:

m_propertyMap.reserveInitialCapacity(static_cast<unsigned>(AXPropertyName::VisibleRows));

Where AXPropertyName::VisibleRows is the last member of the AXPropertyName enum class. But that would assume that every object has every property, which definitely isn't true, and would cause us to over-allocate the hashmap for every object.
Comment 5 Tyler Wilcock 2022-12-24 12:01:56 PST
> > Is there a way to calculate this number less manually
> I don't think so. We could do:
> 
> m_propertyMap.reserveInitialCapacity(static_cast<unsigned>(AXPropertyName::
> VisibleRows));
> 
> Where AXPropertyName::VisibleRows is the last member of the AXPropertyName
> enum class. But that would assume that every object has every property,
> which definitely isn't true, and would cause us to over-allocate the hashmap
> for every object.
Though we could probably do it if we had some structure that defined the properties for each type of object (i.e. something like WebAccessibilityObjectWrapperMac::accessibilityAttributeNames does), rather than the ad-hoc initialization we do now in AXIsolatedObject::initializeProperties.

But sizing the map based on such a structure would be invalidated by sparse property storage, too, so probably not worth the work to do.
Comment 6 EWS 2022-12-24 18:52:52 PST
Committed 258328@main (98a28389be81): <https://commits.webkit.org/258328@main>

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