Changeset 251882 in webkit


Ignore:
Timestamp:
Oct 31, 2019 2:53:18 PM (4 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Make String#localeCompare faster by inlining JSGlobalObject::defaultCollator
https://bugs.webkit.org/show_bug.cgi?id=203696

Reviewed by Mark Lam.

We found that JSGlobalObject::defaultCollator is not inlined and it takes some time in JetStream2/cdjs.
We use LazyProperty mechanism here and make JSGlobalObject::defaultCollator function inlinable simple one.
This patch improves JetStream2/cdjs by 2%.

  • runtime/IntlCollator.cpp:

(JSC::IntlCollator::initializeCollator):

  • runtime/IntlObject.cpp:

(JSC::intlBooleanOption):
(JSC::intlStringOption):
(JSC::intlNumberOption):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
(JSC::JSGlobalObject::defaultCollator): Deleted.

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::defaultCollator const):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncLocaleCompare):

Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r251875 r251882  
     12019-10-31  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Make String#localeCompare faster by inlining JSGlobalObject::defaultCollator
     4        https://bugs.webkit.org/show_bug.cgi?id=203696
     5
     6        Reviewed by Mark Lam.
     7
     8        We found that JSGlobalObject::defaultCollator is not inlined and it takes some time in JetStream2/cdjs.
     9        We use LazyProperty mechanism here and make JSGlobalObject::defaultCollator function inlinable simple one.
     10        This patch improves JetStream2/cdjs by 2%.
     11
     12        * runtime/IntlCollator.cpp:
     13        (JSC::IntlCollator::initializeCollator):
     14        * runtime/IntlObject.cpp:
     15        (JSC::intlBooleanOption):
     16        (JSC::intlStringOption):
     17        (JSC::intlNumberOption):
     18        * runtime/JSGlobalObject.cpp:
     19        (JSC::JSGlobalObject::init):
     20        (JSC::JSGlobalObject::visitChildren):
     21        (JSC::JSGlobalObject::defaultCollator): Deleted.
     22        * runtime/JSGlobalObject.h:
     23        (JSC::JSGlobalObject::defaultCollator const):
     24        * runtime/StringPrototype.cpp:
     25        (JSC::stringProtoFuncLocaleCompare):
     26
    1272019-10-31  Saam Barati  <sbarati@apple.com>
    228
  • trunk/Source/JavaScriptCore/runtime/IntlCollator.cpp

    r251736 r251882  
    185185    RETURN_IF_EXCEPTION(scope, void());
    186186
    187     JSObject* options;
    188     if (optionsValue.isUndefined())
    189         options = constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure());
    190     else {
     187    JSValue options = optionsValue;
     188    if (!optionsValue.isUndefined()) {
    191189        options = optionsValue.toObject(globalObject);
    192190        RETURN_IF_EXCEPTION(scope, void());
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r251425 r251882  
    152152    auto scope = DECLARE_THROW_SCOPE(vm);
    153153
     154    if (options.isUndefined()) {
     155        usesFallback = true;
     156        return false;
     157    }
     158
    154159    JSObject* opts = options.toObject(globalObject);
    155160    RETURN_IF_EXCEPTION(scope, false);
     
    177182    auto scope = DECLARE_THROW_SCOPE(vm);
    178183
     184    if (options.isUndefined())
     185        return fallback;
     186
    179187    JSObject* opts = options.toObject(globalObject);
    180188    RETURN_IF_EXCEPTION(scope, String());
     
    204212    VM& vm = globalObject->vm();
    205213    auto scope = DECLARE_THROW_SCOPE(vm);
     214
     215    if (options.isUndefined())
     216        return fallback;
    206217
    207218    JSObject* opts = options.toObject(globalObject);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r251691 r251882  
    894894            init.set(IntlPluralRules::createStructure(init.vm, globalObject, pluralRulesPrototype));
    895895        });
     896    m_defaultCollator.initLater(
     897        [] (const Initializer<IntlCollator>& init) {
     898            JSGlobalObject* globalObject = jsCast<JSGlobalObject*>(init.owner);
     899            VM& vm = init.vm;
     900            auto scope = DECLARE_CATCH_SCOPE(vm);
     901            IntlCollator* collator = IntlCollator::create(vm, globalObject->collatorStructure());
     902            collator->initializeCollator(globalObject, jsUndefined(), jsUndefined());
     903            scope.releaseAssertNoException();
     904            init.set(collator);
     905        });
    896906
    897907    IntlObject* intl = IntlObject::create(vm, IntlObject::createStructure(vm, this, m_objectPrototype.get()));
     
    16911701
    16921702#if ENABLE(INTL)
    1693     visitor.append(thisObject->m_defaultCollator);
     1703    thisObject->m_defaultCollator.visit(visitor);
    16941704    thisObject->m_collatorStructure.visit(visitor);
    16951705    thisObject->m_numberFormatStructure.visit(visitor);
     
    20612071}
    20622072
    2063 IntlCollator* JSGlobalObject::defaultCollator(JSGlobalObject* globalObject)
    2064 {
    2065     VM& vm = globalObject->vm();
    2066     auto scope = DECLARE_THROW_SCOPE(vm);
    2067 
    2068     if (m_defaultCollator)
    2069         return m_defaultCollator.get();
    2070 
    2071     IntlCollator* collator = IntlCollator::create(vm, collatorStructure());
    2072     collator->initializeCollator(globalObject, jsUndefined(), jsUndefined());
    2073     RETURN_IF_EXCEPTION(scope, nullptr);
    2074     m_defaultCollator.set(vm, this, collator);
    2075     return collator;
    2076 }
    2077 
    20782073#endif // ENABLE(INTL)
    20792074
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r251691 r251882  
    286286
    287287#if ENABLE(INTL)
    288     WriteBarrier<IntlCollator> m_defaultCollator;
     288    LazyProperty<JSGlobalObject, IntlCollator> m_defaultCollator;
    289289    LazyProperty<JSGlobalObject, Structure> m_collatorStructure;
    290290    LazyProperty<JSGlobalObject, Structure> m_numberFormatStructure;
     
    607607
    608608#if ENABLE(INTL)
    609     IntlCollator* defaultCollator(JSGlobalObject*);
     609    IntlCollator* defaultCollator() const { return m_defaultCollator.get(this); }
    610610#endif
    611611
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r251518 r251882  
    15041504    JSValue options = callFrame->argument(2);
    15051505    IntlCollator* collator = nullptr;
    1506     if (locales.isUndefined() && options.isUndefined()) {
    1507         collator = globalObject->defaultCollator(globalObject);
    1508         RETURN_IF_EXCEPTION(scope, encodedJSValue());
    1509     } else {
     1506    if (locales.isUndefined() && options.isUndefined())
     1507        collator = globalObject->defaultCollator();
     1508    else {
    15101509        collator = IntlCollator::create(vm, globalObject->collatorStructure());
    15111510        collator->initializeCollator(globalObject, locales, options);
Note: See TracChangeset for help on using the changeset viewer.