Bug 239545

Summary: Avoid call to convertToASCIILowercase() in SelectorFilter::collectElementIdentifierHashes() in the common case
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, darin, esprehn+autocc, ews-watchlist, ggaren, glenn, gyuyoung.kim, macpherson, menard, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Chris Dumez 2022-04-20 09:08:45 PDT
Avoid call to convertToASCIILowercase() in SelectorFilter::collectElementIdentifierHashes() in the common case.
Comment 1 Chris Dumez 2022-04-20 09:12:51 PDT
Created attachment 457993 [details]
Patch
Comment 2 Sam Weinig 2022-04-20 14:42:49 PDT
Comment on attachment 457993 [details]
Patch

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

> Source/WebCore/css/SelectorFilter.cpp:50
> +    AtomString tagLowercaseLocalName = LIKELY(element.isHTMLElement() && !element.isUnknownElement()) ? element.localName() : element.localName().convertToASCIILowercase();

A comment explaining this assumption would be useful even with the assert.
Comment 3 EWS 2022-04-20 15:12:34 PDT
Committed r293123 (249826@main): <https://commits.webkit.org/249826@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457993 [details].
Comment 4 Radar WebKit Bug Importer 2022-04-20 15:13:29 PDT
<rdar://problem/92054703>
Comment 5 Darin Adler 2022-04-20 17:44:46 PDT
Comment on attachment 457993 [details]
Patch

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

>> Source/WebCore/css/SelectorFilter.cpp:50
>> +    AtomString tagLowercaseLocalName = LIKELY(element.isHTMLElement() && !element.isUnknownElement()) ? element.localName() : element.localName().convertToASCIILowercase();
> 
> A comment explaining this assumption would be useful even with the assert.

The classic way to do this is to write a function named localNameIsKnownToBeLowercase or localNameMayContainUppercaseASCII. Then that function is the perfect place for the comment explaining why the rule is correct, and here the code is more obviously correct.
Comment 6 Chris Dumez 2022-04-20 18:10:49 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 457993 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457993&action=review
> 
> >> Source/WebCore/css/SelectorFilter.cpp:50
> >> +    AtomString tagLowercaseLocalName = LIKELY(element.isHTMLElement() && !element.isUnknownElement()) ? element.localName() : element.localName().convertToASCIILowercase();
> > 
> > A comment explaining this assumption would be useful even with the assert.
> 
> The classic way to do this is to write a function named
> localNameIsKnownToBeLowercase or localNameMayContainUppercaseASCII. Then
> that function is the perfect place for the comment explaining why the rule
> is correct, and here the code is more obviously correct.

Oh, I missed Sam's comment before landing. Sorry about that. I'll follow-up.
Comment 7 Chris Dumez 2022-04-20 18:52:27 PDT
0.38% progression on Speedometer on Intel, neutral on Apple Silicon.
Comment 8 Chris Dumez 2022-04-20 19:08:43 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 457993 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457993&action=review
> 
> >> Source/WebCore/css/SelectorFilter.cpp:50
> >> +    AtomString tagLowercaseLocalName = LIKELY(element.isHTMLElement() && !element.isUnknownElement()) ? element.localName() : element.localName().convertToASCIILowercase();
> > 
> > A comment explaining this assumption would be useful even with the assert.
> 
> The classic way to do this is to write a function named
> localNameIsKnownToBeLowercase or localNameMayContainUppercaseASCII. Then
> that function is the perfect place for the comment explaining why the rule
> is correct, and here the code is more obviously correct.

Done in <https://commits.webkit.org/r293138>.