⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268852 in webkit


Ignore:
Timestamp:
Oct 21, 2020, 9:50:33 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Replace O(n2) algorithm from r268709 with O(n) algorithm
https://bugs.webkit.org/show_bug.cgi?id=218062

Patch by Alex Christensen <achristensen@webkit.org> on 2020-10-21
Reviewed by Alexey Shvayka.

r268709 introduced a Vector::findMatching call inside a loop that populates the Vector.
This causes very slow construction of URLSearchParams with large dictionaries with 16-bit keys.
To speed things up, keep a HashMap of the 16-bit strings we have already inserted to their index in the Vector
so we don't need to search the Vector.

  • bindings/js/JSDOMConvertRecord.h:
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268850 r268852  
     12020-10-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        Replace O(n^2) algorithm from r268709 with O(n) algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=218062
     5
     6        Reviewed by Alexey Shvayka.
     7
     8        r268709 introduced a Vector::findMatching call inside a loop that populates the Vector.
     9        This causes very slow construction of URLSearchParams with large dictionaries with 16-bit keys.
     10        To speed things up, keep a HashMap of the 16-bit strings we have already inserted to their index in the Vector
     11        so we don't need to search the Vector.
     12
     13        * bindings/js/JSDOMConvertRecord.h:
     14
    1152020-10-21  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    216
  • trunk/Source/WebCore/bindings/js/JSDOMConvertRecord.h

    r268709 r268852  
    9797   
    9898        ReturnType result;
     99        HashMap<KeyType, size_t> resultMap;
    99100   
    100101        // 4. Let keys be ? O.[[OwnPropertyKeys]]().
     
    132133                if constexpr (std::is_same_v<K, IDLUSVString>) {
    133134                    if (!typedKey.is8Bit()) {
    134                         auto index = result.findMatching([&](auto& entry) { return entry.key == typedKey; });
    135                         if (index != notFound) {
    136                             result[index].value = typedValue;
     135                        auto iterator = resultMap.find(typedKey);
     136                        if (iterator != resultMap.end()) {
     137                            ASSERT(result[iterator->value].key == typedKey);
     138                            result[iterator->value].value = WTFMove(typedValue);
    137139                            continue;
    138140                        }
     141                        resultMap.add(typedKey, result.size());
    139142                    }
    140                 }
     143                } else
     144                    UNUSED_VARIABLE(resultMap);
    141145               
    142                 result.append({ typedKey, typedValue });
     146                // 5. Otherwise, append to result a mapping (typedKey, typedValue).
     147                result.append({ WTFMove(typedKey), WTFMove(typedValue) });
    143148            }
    144149        }
Note: See TracChangeset for help on using the changeset viewer.