Bug 249873 - AX: Pre-size AXIsolatedObject::m_propertyMap to avoid unnecessary HashTable reallocations
Summary: AX: Pre-size AXIsolatedObject::m_propertyMap to avoid unnecessary HashTable r...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tyler Wilcock
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-12-24 11:37 PST by Tyler Wilcock
Modified: 2022-12-24 18:52 PST (History)
10 users (show)

See Also:


Attachments
Patch (4.62 KB, patch)
2022-12-24 11:42 PST, 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-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].