Changeset 167577 in webkit


Ignore:
Timestamp:
Apr 20, 2014 9:19:07 PM (10 years ago)
Author:
akling@apple.com
Message:

Speed up jsStringWithCache() through WeakGCMap inlining.
<https://webkit.org/b/131923>

Source/JavaScriptCore:
Always inline WeakGCMap::add() but move the slow garbage collecting
path out-of-line.

Reviewed by Darin Adler.

  • runtime/WeakGCMap.h:

(JSC::WeakGCMap::add):
(JSC::WeakGCMap::gcMap):

Source/WebCore:
Inline the common path of WeakGCMap::add() in jsStringWithCache().
26% progression on Bindings/id-getter.html

Reviewed by Darin Adler.

  • WebCore.exp.in:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMBinding.cpp:

(WebCore::jsStringWithCache):

Move jsStringWithCache() out of line since we're now blowing up
its size quite a bit.

Source/WTF:
Add HashMap::fastAdd(), which is the same as add() except we'll tell
the compiler to aggressively inline it.

Reviewed by Darin Adler.

  • wtf/HashMap.h:
  • wtf/HashTable.h:
Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r167566 r167577  
     12014-04-20  Andreas Kling  <akling@apple.com>
     2
     3        Speed up jsStringWithCache() through WeakGCMap inlining.
     4        <https://webkit.org/b/131923>
     5
     6        Always inline WeakGCMap::add() but move the slow garbage collecting
     7        path out-of-line.
     8
     9        Reviewed by Darin Adler.
     10
     11        * runtime/WeakGCMap.h:
     12        (JSC::WeakGCMap::add):
     13        (JSC::WeakGCMap::gcMap):
     14
    1152014-04-20  László Langó  <llango.u-szeged@partner.samsung.com>
    216
  • trunk/Source/JavaScriptCore/runtime/WeakGCMap.h

    r157688 r167577  
    6363    }
    6464
    65     AddResult add(const KeyType& key, ValueType value)
     65    ALWAYS_INLINE AddResult add(const KeyType& key, ValueType value)
    6666    {
    6767        gcMapIfNeeded();
    68         AddResult addResult = m_map.add(key, nullptr);
     68        AddResult addResult = m_map.fastAdd(key, nullptr);
    6969        if (!addResult.iterator->value) { // New value or found a zombie value.
    7070            addResult.isNewEntry = true;
     
    106106    static const int minGCThreshold = 3;
    107107
    108     void gcMap()
     108    NEVER_INLINE void gcMap()
    109109    {
    110110        Vector<KeyType, 4> zombies;
  • trunk/Source/WTF/ChangeLog

    r167548 r167577  
     12014-04-20  Andreas Kling  <akling@apple.com>
     2
     3        Speed up jsStringWithCache() through WeakGCMap inlining.
     4        <https://webkit.org/b/131923>
     5
     6        Add HashMap::fastAdd(), which is the same as add() except we'll tell
     7        the compiler to aggressively inline it.
     8
     9        Reviewed by Darin Adler.
     10
     11        * wtf/HashMap.h:
     12        * wtf/HashTable.h:
     13
    1142014-04-19  Filip Pizlo  <fpizlo@apple.com>
    215
  • trunk/Source/WTF/wtf/HashMap.h

    r163519 r167577  
    115115    template<typename V> AddResult add(KeyType&&, V&&);
    116116
     117    // Same as add(), but aggressively inlined.
     118    template<typename V> AddResult fastAdd(const KeyType&, V&&);
     119    template<typename V> AddResult fastAdd(KeyType&&, V&&);
     120
    117121    bool remove(const KeyType&);
    118122    bool remove(iterator);
     
    277281template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
    278282template<typename K, typename V>
    279 auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(K&& key, V&& value) -> AddResult
     283ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(K&& key, V&& value) -> AddResult
    280284{
    281285    return m_impl.template add<HashMapTranslator<KeyValuePairTraits, HashFunctions>>(std::forward<K>(key), std::forward<V>(value));
     
    313317template<typename T>
    314318auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::add(KeyType&& key, T&& mapped) -> AddResult
     319{
     320    return inlineAdd(std::move(key), std::forward<T>(mapped));
     321}
     322
     323template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
     324template<typename T>
     325ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::fastAdd(const KeyType& key, T&& mapped) -> AddResult
     326{
     327    return inlineAdd(key, std::forward<T>(mapped));
     328}
     329
     330template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
     331template<typename T>
     332ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::fastAdd(KeyType&& key, T&& mapped) -> AddResult
    315333{
    316334    return inlineAdd(std::move(key), std::forward<T>(mapped));
  • trunk/Source/WTF/wtf/HashTable.h

    r164378 r167577  
    784784    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
    785785    template<typename HashTranslator, typename T, typename Extra>
    786     inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::add(T&& key, Extra&& extra) -> AddResult
     786    ALWAYS_INLINE auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::add(T&& key, Extra&& extra) -> AddResult
    787787    {
    788788        checkKey<HashTranslator>(key);
  • trunk/Source/WebCore/ChangeLog

    r167575 r167577  
     12014-04-20  Andreas Kling  <akling@apple.com>
     2
     3        Speed up jsStringWithCache() through WeakGCMap inlining.
     4        <https://webkit.org/b/131923>
     5
     6        Inline the common path of WeakGCMap::add() in jsStringWithCache().
     7        26% progression on Bindings/id-getter.html
     8
     9        Reviewed by Darin Adler.
     10
     11        * WebCore.exp.in:
     12        * bindings/js/JSDOMBinding.h:
     13        * bindings/js/JSDOMBinding.cpp:
     14        (WebCore::jsStringWithCache):
     15
     16            Move jsStringWithCache() out of line since we're now blowing up
     17            its size quite a bit.
     18
    1192014-04-20  Benjamin Poulain  <benjamin@webkit.org>
    220
  • trunk/Source/WebCore/WebCore.exp.in

    r167568 r167577  
    747747__ZN7WebCore17drawLayerContentsEP9CGContextPNS_15PlatformCALayerERN3WTF6VectorINS_9FloatRectELm5ENS4_15CrashOnOverflowEEE
    748748__ZN7WebCore17encodeForFileNameERKN3WTF6StringE
     749__ZN7WebCore17jsStringWithCacheEPN3JSC9ExecStateERKN3WTF6StringE
    749750__ZN7WebCore17languageDidChangeEv
    750751__ZN7WebCore17openTemporaryFileERKN3WTF6StringERi
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp

    r166864 r167577  
    6464}
    6565
     66JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
     67{
     68    StringImpl* stringImpl = s.impl();
     69    if (!stringImpl || !stringImpl->length())
     70        return jsEmptyString(exec);
     71
     72    if (stringImpl->length() == 1) {
     73        UChar singleCharacter = (*stringImpl)[0u];
     74        if (singleCharacter <= JSC::maxSingleCharacterString) {
     75            JSC::VM* vm = &exec->vm();
     76            return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
     77        }
     78    }
     79
     80    JSStringCache& stringCache = currentWorld(exec).m_stringCache;
     81    JSStringCache::AddResult addResult = stringCache.add(stringImpl, nullptr);
     82    if (addResult.isNewEntry)
     83        addResult.iterator->value = JSC::jsString(exec, String(stringImpl));
     84    return JSC::JSValue(addResult.iterator->value.get());
     85}
     86
    6687JSValue jsStringOrNull(ExecState* exec, const String& s)
    6788{
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r166864 r167577  
    560560JSC::EncodedJSValue objectToStringFunctionGetter(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
    561561
    562 inline JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
    563 {
    564     StringImpl* stringImpl = s.impl();
    565     if (!stringImpl || !stringImpl->length())
    566         return jsEmptyString(exec);
    567 
    568     if (stringImpl->length() == 1) {
    569         UChar singleCharacter = (*stringImpl)[0u];
    570         if (singleCharacter <= JSC::maxSingleCharacterString) {
    571             JSC::VM* vm = &exec->vm();
    572             return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
    573         }
    574     }
    575 
    576     JSStringCache& stringCache = currentWorld(exec).m_stringCache;
    577     JSStringCache::AddResult addResult = stringCache.add(stringImpl, nullptr);
    578     if (addResult.isNewEntry)
    579         addResult.iterator->value = JSC::jsString(exec, String(stringImpl));
    580     return JSC::JSValue(addResult.iterator->value.get());
    581 }
    582 
    583562inline String propertyNameToString(JSC::PropertyName propertyName)
    584563{
Note: See TracChangeset for help on using the changeset viewer.