Ignore:
Timestamp:
Oct 29, 2019, 2:43:30 PM (6 years ago)
Author:
[email protected]
Message:

[JSC] Add fast path for String#localeCompare
https://bugs.webkit.org/show_bug.cgi?id=202676

Reviewed by Mark Lam.

JSTests:

  • stress/locale-compare-bits.js: Added.

(shouldBe):

Source/JavaScriptCore:

When String#localeCompare is invoked, we are setting up UCharIterator to iterate code points.
But this is too slow since its implementation is invoking function pointer for each code point
to get next code point. Strings have many code points typically. Invoking function pointer so many times
takes too much time just for locale-aware comparison.

This patch revises the implementation by adding 2 fast path and 1 slow path. The slow path requires extra memory,
but it is soon released (not GC-managed).

  1. If both strings are ASCII (not Latin1), we use ucol_strcollUTF8.
  2. If both strings are 16-bit, we use ucol_strcoll.
  3. Otherwise, we convert strings to 16-bit strings, and then we use ucol_strcoll.

JetStream2/cdjs is improved from 56 to 85 on iMac Pro (50%).

  • runtime/IntlCollator.cpp:

(JSC::IntlCollator::compareStrings):

  • tools/JSDollarVM.cpp:

(JSC::functionMake16BitStringIfPossible):
(JSC::JSDollarVM::finishCreation):

Source/WTF:

  • wtf/text/StringView.h:

(WTF::StringView::isAllASCII const):

Tools:

  • TestWebKitAPI/Tests/WTF/StringView.cpp:

(TestWebKitAPI::TEST):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/JSDollarVM.cpp

    r251518 r251736  
    25562556}
    25572557
     2558static EncodedJSValue JSC_HOST_CALL functionMake16BitStringIfPossible(JSGlobalObject* globalObject, CallFrame* callFrame)
     2559{
     2560    DollarVMAssertScope assertScope;
     2561    VM& vm = globalObject->vm();
     2562    auto scope = DECLARE_THROW_SCOPE(vm);
     2563    String string = callFrame->argument(0).toWTFString(globalObject);
     2564    RETURN_IF_EXCEPTION(scope, { });
     2565    if (!string.is8Bit())
     2566        return JSValue::encode(jsString(vm, WTFMove(string)));
     2567    Vector<UChar> buffer;
     2568    buffer.resize(string.length());
     2569    StringImpl::copyCharacters(buffer.data(), string.characters8(), string.length());
     2570    return JSValue::encode(jsString(vm, String::adopt(WTFMove(buffer))));
     2571}
     2572
    25582573void JSDollarVM::finishCreation(VM& vm)
    25592574{
     
    26782693
    26792694    addFunction(vm, "isWasmSupported", functionIsWasmSupported, 0);
     2695    addFunction(vm, "make16BitStringIfPossible", functionMake16BitStringIfPossible, 1);
    26802696}
    26812697
Note: See TracChangeset for help on using the changeset viewer.