Bug 225223

Summary: Optimize SortedArrayMap by using linear search for small arrays
Product: WebKit Reporter: Darin Adler <darin>
Component: Web Template FrameworkAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, ews-watchlist, sam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Description Darin Adler 2021-04-29 19:17:55 PDT
Optimize SortedArrayMap by using linear search for small arrays
Comment 1 Darin Adler 2021-04-29 19:21:09 PDT
Created attachment 427396 [details]
Patch
Comment 2 Yusuke Suzuki 2021-04-29 22:02:01 PDT
Comment on attachment 427396 [details]
Patch

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

r=me

> Source/WTF/wtf/SortedArrayMap.h:145
> +    if (std::size(m_array) < binarySearchThreshold) {

How about making it `if constexpr` to ensure that this dispatching is done at compile time.

> Source/WTF/wtf/SortedArrayMap.h:177
> +    if (std::size(m_array) < binarySearchThreshold)

Ditto.
Comment 3 Darin Adler 2021-04-30 08:57:57 PDT
Comment on attachment 427396 [details]
Patch

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

>> Source/WTF/wtf/SortedArrayMap.h:145
>> +    if (std::size(m_array) < binarySearchThreshold) {
> 
> How about making it `if constexpr` to ensure that this dispatching is done at compile time.

Tried if constexpr first. The compiler gave an error saying that I could not use "this" in it, so I would have had to find some way to get the size from the type rather than from m_array. Decided to leave it non-constexpr; still gets constant-folded.
Comment 4 Darin Adler 2021-04-30 08:58:49 PDT
Comment on attachment 427396 [details]
Patch

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

>>> Source/WTF/wtf/SortedArrayMap.h:145
>>> +    if (std::size(m_array) < binarySearchThreshold) {
>> 
>> How about making it `if constexpr` to ensure that this dispatching is done at compile time.
> 
> Tried if constexpr first. The compiler gave an error saying that I could not use "this" in it, so I would have had to find some way to get the size from the type rather than from m_array. Decided to leave it non-constexpr; still gets constant-folded.

If you help me find a clean simple way for me to move to if constexpr without making the code ugly, would be happy to come back and do that later.
Comment 5 EWS 2021-04-30 09:02:59 PDT
Committed r276840 (237191@main): <https://commits.webkit.org/237191@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 427396 [details].
Comment 6 Radar WebKit Bug Importer 2021-04-30 09:03:27 PDT
<rdar://problem/77385092>