Bug 239406 - Optimize id matching in AccessibilityObject::ariaElementsReferencedByAttribute()
Summary: Optimize id matching in AccessibilityObject::ariaElementsReferencedByAttribute()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-15 14:28 PDT by Chris Dumez
Modified: 2022-04-17 00:02 PDT (History)
16 users (show)

See Also:


Attachments
Patch (9.03 KB, patch)
2022-04-15 14:35 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2022-04-15 14:28:50 PDT
Optimize id matching in AccessibilityObject::ariaElementsReferencedByAttribute().
Comment 1 Radar WebKit Bug Importer 2022-04-15 14:28:59 PDT
<rdar://problem/91829358>
Comment 2 Chris Dumez 2022-04-15 14:35:39 PDT
Created attachment 457726 [details]
Patch
Comment 3 Darin Adler 2022-04-15 16:13:09 PDT
Comment on attachment 457726 [details]
Patch

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

> Source/WebCore/accessibility/AccessibilityObject.cpp:3932
> +        if (!SpaceSplitString::spaceSplitStringContainsValue(idList, id))
>              continue;

If we are going to walk an entire DOM tree and check every attribute value against a set, I think we should probably convert it into a HashSet<AtomString>, don’t you?
Comment 4 Chris Dumez 2022-04-15 16:19:27 PDT
Comment on attachment 457726 [details]
Patch

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

>> Source/WebCore/accessibility/AccessibilityObject.cpp:3932
>>              continue;
> 
> If we are going to walk an entire DOM tree and check every attribute value against a set, I think we should probably convert it into a HashSet<AtomString>, don’t you?

I don't understand the comment and how I can leverage a HashSet<AtomString>.

We have a string stored in the variable 'id', we want to iterate the whole DOM tree and find all Elements that have that id string in their attribute |attribute| (which is one of the few aria- attributes). Another tricky thing is that apparently, the value of |attribute| is a HTMLSpace-separated string and we want to know if any of the substrings in that attribute value match the string stored in id.
Seems to me that the implementation I have now is pretty efficient given the current constraints?

Ideally, at some point, we wouldn't need to iterate the whole DOM tree and we'd know which elements may match ahead of time. I talked to Tyler about that and he said that's on his TODO list.
Comment 5 Darin Adler 2022-04-15 16:46:02 PDT
Comment on attachment 457726 [details]
Patch

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

>>> Source/WebCore/accessibility/AccessibilityObject.cpp:3932
>>>              continue;
>> 
>> If we are going to walk an entire DOM tree and check every attribute value against a set, I think we should probably convert it into a HashSet<AtomString>, don’t you?
> 
> I don't understand the comment and how I can leverage a HashSet<AtomString>.
> 
> We have a string stored in the variable 'id', we want to iterate the whole DOM tree and find all Elements that have that id string in their attribute |attribute| (which is one of the few aria- attributes). Another tricky thing is that apparently, the value of |attribute| is a HTMLSpace-separated string and we want to know if any of the substrings in that attribute value match the string stored in id.
> Seems to me that the implementation I have now is pretty efficient given the current constraints?
> 
> Ideally, at some point, we wouldn't need to iterate the whole DOM tree and we'd know which elements may match ahead of time. I talked to Tyler about that and he said that's on his TODO list.

Oh, I didn’t realize that the attributes from each element were the things we're splitting!
Comment 6 Chris Dumez 2022-04-15 16:46:23 PDT
(In reply to Chris Dumez from comment #4)
> Comment on attachment 457726 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457726&action=review
> 
> >> Source/WebCore/accessibility/AccessibilityObject.cpp:3932
> >>              continue;
> > 
> > If we are going to walk an entire DOM tree and check every attribute value against a set, I think we should probably convert it into a HashSet<AtomString>, don’t you?
> 
> I don't understand the comment and how I can leverage a HashSet<AtomString>.
> 
> We have a string stored in the variable 'id', we want to iterate the whole
> DOM tree and find all Elements that have that id string in their attribute
> |attribute| (which is one of the few aria- attributes). Another tricky thing
> is that apparently, the value of |attribute| is a HTMLSpace-separated string
> and we want to know if any of the substrings in that attribute value match
> the string stored in id.
> Seems to me that the implementation I have now is pretty efficient given the
> current constraints?
> 
> Ideally, at some point, we wouldn't need to iterate the whole DOM tree and
> we'd know which elements may match ahead of time. I talked to Tyler about
> that and he said that's on his TODO list.

I think the misunderstanding may be that each Element in the DOM tree has a list of ids as a space-separate attribute value, and we're matching them against a single id string.

If it was the other way around (each element has a single id and we need to match against a list of ids we have), then a HashSet<AtomString> for the list of ids we have would totally make sense.
Comment 7 Darin Adler 2022-04-15 16:55:42 PDT
(In reply to Chris Dumez from comment #6)
> I think the misunderstanding may be that each Element in the DOM tree has a
> list of ids as a space-separate attribute value, and we're matching them
> against a single id string.

Yes, that was it.
Comment 8 EWS 2022-04-16 16:00:27 PDT
Committed r292943 (249708@main): <https://commits.webkit.org/249708@main>

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