Title: [167577] trunk/Source
Revision
167577
Author
[email protected]
Date
2014-04-20 21:19:07 -0700 (Sun, 20 Apr 2014)

Log Message

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

Source/_javascript_Core:
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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (167576 => 167577)


--- trunk/Source/_javascript_Core/ChangeLog	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-04-21 04:19:07 UTC (rev 167577)
@@ -1,3 +1,17 @@
+2014-04-20  Andreas Kling  <[email protected]>
+
+        Speed up jsStringWithCache() through WeakGCMap inlining.
+        <https://webkit.org/b/131923>
+
+        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):
+
 2014-04-20  László Langó  <[email protected]>
 
         _javascript_Core: ARM build fix after r167094.

Modified: trunk/Source/_javascript_Core/runtime/WeakGCMap.h (167576 => 167577)


--- trunk/Source/_javascript_Core/runtime/WeakGCMap.h	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/_javascript_Core/runtime/WeakGCMap.h	2014-04-21 04:19:07 UTC (rev 167577)
@@ -62,10 +62,10 @@
         return m_map.set(key, std::move(value));
     }
 
-    AddResult add(const KeyType& key, ValueType value)
+    ALWAYS_INLINE AddResult add(const KeyType& key, ValueType value)
     {
         gcMapIfNeeded();
-        AddResult addResult = m_map.add(key, nullptr);
+        AddResult addResult = m_map.fastAdd(key, nullptr);
         if (!addResult.iterator->value) { // New value or found a zombie value.
             addResult.isNewEntry = true;
             addResult.iterator->value = std::move(value);
@@ -105,7 +105,7 @@
 private:
     static const int minGCThreshold = 3;
 
-    void gcMap()
+    NEVER_INLINE void gcMap()
     {
         Vector<KeyType, 4> zombies;
 

Modified: trunk/Source/WTF/ChangeLog (167576 => 167577)


--- trunk/Source/WTF/ChangeLog	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WTF/ChangeLog	2014-04-21 04:19:07 UTC (rev 167577)
@@ -1,3 +1,16 @@
+2014-04-20  Andreas Kling  <[email protected]>
+
+        Speed up jsStringWithCache() through WeakGCMap inlining.
+        <https://webkit.org/b/131923>
+
+        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:
+
 2014-04-19  Filip Pizlo  <[email protected]>
 
         Make it easier to check if an integer sum would overflow

Modified: trunk/Source/WTF/wtf/HashMap.h (167576 => 167577)


--- trunk/Source/WTF/wtf/HashMap.h	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WTF/wtf/HashMap.h	2014-04-21 04:19:07 UTC (rev 167577)
@@ -114,6 +114,10 @@
     template<typename V> AddResult add(const KeyType&, V&&);
     template<typename V> AddResult add(KeyType&&, V&&);
 
+    // Same as add(), but aggressively inlined.
+    template<typename V> AddResult fastAdd(const KeyType&, V&&);
+    template<typename V> AddResult fastAdd(KeyType&&, V&&);
+
     bool remove(const KeyType&);
     bool remove(iterator);
     void clear();
@@ -276,7 +280,7 @@
 
 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
 template<typename K, typename V>
-auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(K&& key, V&& value) -> AddResult
+ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(K&& key, V&& value) -> AddResult
 {
     return m_impl.template add<HashMapTranslator<KeyValuePairTraits, HashFunctions>>(std::forward<K>(key), std::forward<V>(value));
 }
@@ -316,6 +320,20 @@
     return inlineAdd(std::move(key), std::forward<T>(mapped));
 }
 
+template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
+template<typename T>
+ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::fastAdd(const KeyType& key, T&& mapped) -> AddResult
+{
+    return inlineAdd(key, std::forward<T>(mapped));
+}
+
+template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
+template<typename T>
+ALWAYS_INLINE auto HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::fastAdd(KeyType&& key, T&& mapped) -> AddResult
+{
+    return inlineAdd(std::move(key), std::forward<T>(mapped));
+}
+
 template<typename T, typename U, typename V, typename W, typename MappedTraits>
 auto HashMap<T, U, V, W, MappedTraits>::get(const KeyType& key) const -> MappedPeekType
 {

Modified: trunk/Source/WTF/wtf/HashTable.h (167576 => 167577)


--- trunk/Source/WTF/wtf/HashTable.h	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WTF/wtf/HashTable.h	2014-04-21 04:19:07 UTC (rev 167577)
@@ -783,7 +783,7 @@
 
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     template<typename HashTranslator, typename T, typename Extra>
-    inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::add(T&& key, Extra&& extra) -> AddResult
+    ALWAYS_INLINE auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::add(T&& key, Extra&& extra) -> AddResult
     {
         checkKey<HashTranslator>(key);
 

Modified: trunk/Source/WebCore/ChangeLog (167576 => 167577)


--- trunk/Source/WebCore/ChangeLog	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WebCore/ChangeLog	2014-04-21 04:19:07 UTC (rev 167577)
@@ -1,3 +1,21 @@
+2014-04-20  Andreas Kling  <[email protected]>
+
+        Speed up jsStringWithCache() through WeakGCMap inlining.
+        <https://webkit.org/b/131923>
+
+        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.
+
 2014-04-20  Benjamin Poulain  <[email protected]>
 
         Fix the build after r167574

Modified: trunk/Source/WebCore/WebCore.exp.in (167576 => 167577)


--- trunk/Source/WebCore/WebCore.exp.in	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-04-21 04:19:07 UTC (rev 167577)
@@ -746,6 +746,7 @@
 __ZN7WebCore17cacheDOMStructureEPNS_17JSDOMGlobalObjectEPN3JSC9StructureEPKNS2_9ClassInfoE
 __ZN7WebCore17drawLayerContentsEP9CGContextPNS_15PlatformCALayerERN3WTF6VectorINS_9FloatRectELm5ENS4_15CrashOnOverflowEEE
 __ZN7WebCore17encodeForFileNameERKN3WTF6StringE
+__ZN7WebCore17jsStringWithCacheEPN3JSC9ExecStateERKN3WTF6StringE
 __ZN7WebCore17languageDidChangeEv
 __ZN7WebCore17openTemporaryFileERKN3WTF6StringERi
 __ZN7WebCore17sRGBColorSpaceRefEv

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (167576 => 167577)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2014-04-21 04:19:07 UTC (rev 167577)
@@ -63,6 +63,27 @@
     return DOMObjectHashTableMap::mapFor(vm).get(staticTable);
 }
 
+JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
+{
+    StringImpl* stringImpl = s.impl();
+    if (!stringImpl || !stringImpl->length())
+        return jsEmptyString(exec);
+
+    if (stringImpl->length() == 1) {
+        UChar singleCharacter = (*stringImpl)[0u];
+        if (singleCharacter <= JSC::maxSingleCharacterString) {
+            JSC::VM* vm = &exec->vm();
+            return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
+        }
+    }
+
+    JSStringCache& stringCache = currentWorld(exec).m_stringCache;
+    JSStringCache::AddResult addResult = stringCache.add(stringImpl, nullptr);
+    if (addResult.isNewEntry)
+        addResult.iterator->value = JSC::jsString(exec, String(stringImpl));
+    return JSC::JSValue(addResult.iterator->value.get());
+}
+
 JSValue jsStringOrNull(ExecState* exec, const String& s)
 {
     if (s.isNull())

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (167576 => 167577)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2014-04-20 22:45:38 UTC (rev 167576)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2014-04-21 04:19:07 UTC (rev 167577)
@@ -559,27 +559,6 @@
 void printErrorMessageForFrame(Frame*, const String& message);
 JSC::EncodedJSValue objectToStringFunctionGetter(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
 
-inline JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s)
-{
-    StringImpl* stringImpl = s.impl();
-    if (!stringImpl || !stringImpl->length())
-        return jsEmptyString(exec);
-
-    if (stringImpl->length() == 1) {
-        UChar singleCharacter = (*stringImpl)[0u];
-        if (singleCharacter <= JSC::maxSingleCharacterString) {
-            JSC::VM* vm = &exec->vm();
-            return vm->smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter));
-        }
-    }
-
-    JSStringCache& stringCache = currentWorld(exec).m_stringCache;
-    JSStringCache::AddResult addResult = stringCache.add(stringImpl, nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = JSC::jsString(exec, String(stringImpl));
-    return JSC::JSValue(addResult.iterator->value.get());
-}
-
 inline String propertyNameToString(JSC::PropertyName propertyName)
 {
     return propertyName.publicName();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to