Title: [222929] trunk/Source/_javascript_Core
Revision
222929
Author
[email protected]
Date
2017-10-05 12:58:08 -0700 (Thu, 05 Oct 2017)

Log Message

Only add prototypes to the PrototypeMap if they're not already present
https://bugs.webkit.org/show_bug.cgi?id=177952

Reviewed by Michael Saboff and JF Bastien.

With poly proto, we need to call PrototypeMap::add more frequently since we don't
know if the prototype is already in the map or not based solely on Structure.
PrototypeMap::add was calling WeakMap::set unconditionally, which would unconditionally
allocate a Weak handle. Allocating a Weak handle is expensive. It's at least 8x more
expensive than just checking if the prototype is in the map prior to adding it. This
patch makes the change to only add the prototype if it's not already in the map. To
do this, I've added a WeakMap::add API that just forwards into HashMap's add API.
This allows us to both only do a single hash table lookup and also to allocate only
a single Weak handle when necessary.

* runtime/PrototypeMapInlines.h:
(JSC::PrototypeMap::addPrototype):
* runtime/WeakGCMap.h:
(JSC::WeakGCMap::add):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (222928 => 222929)


--- trunk/Source/_javascript_Core/ChangeLog	2017-10-05 19:12:04 UTC (rev 222928)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-10-05 19:58:08 UTC (rev 222929)
@@ -1,5 +1,27 @@
 2017-10-05  Saam Barati  <[email protected]>
 
+        Only add prototypes to the PrototypeMap if they're not already present
+        https://bugs.webkit.org/show_bug.cgi?id=177952
+
+        Reviewed by Michael Saboff and JF Bastien.
+
+        With poly proto, we need to call PrototypeMap::add more frequently since we don't
+        know if the prototype is already in the map or not based solely on Structure.
+        PrototypeMap::add was calling WeakMap::set unconditionally, which would unconditionally
+        allocate a Weak handle. Allocating a Weak handle is expensive. It's at least 8x more
+        expensive than just checking if the prototype is in the map prior to adding it. This
+        patch makes the change to only add the prototype if it's not already in the map. To
+        do this, I've added a WeakMap::add API that just forwards into HashMap's add API.
+        This allows us to both only do a single hash table lookup and also to allocate only
+        a single Weak handle when necessary.
+
+        * runtime/PrototypeMapInlines.h:
+        (JSC::PrototypeMap::addPrototype):
+        * runtime/WeakGCMap.h:
+        (JSC::WeakGCMap::add):
+
+2017-10-05  Saam Barati  <[email protected]>
+
         Unreviewed. Disable probe OSR exit on 32-bit until it's fixed.
 
         * runtime/Options.cpp:

Modified: trunk/Source/_javascript_Core/runtime/PrototypeMapInlines.h (222928 => 222929)


--- trunk/Source/_javascript_Core/runtime/PrototypeMapInlines.h	2017-10-05 19:12:04 UTC (rev 222928)
+++ trunk/Source/_javascript_Core/runtime/PrototypeMapInlines.h	2017-10-05 19:58:08 UTC (rev 222929)
@@ -44,7 +44,11 @@
 
 ALWAYS_INLINE void PrototypeMap::addPrototype(JSObject* object)
 {
-    m_prototypes.set(object, object);
+    auto addResult = m_prototypes.add(object, Weak<JSObject>());
+    if (addResult.isNewEntry)
+        addResult.iterator->value = Weak<JSObject>(object);
+    else
+        ASSERT(addResult.iterator->value.get() == object);
 
     // Note that this method makes the somewhat odd decision to not check if this
     // object currently has indexed accessors. We could do that check here, and if

Modified: trunk/Source/_javascript_Core/runtime/WeakGCMap.h (222928 => 222929)


--- trunk/Source/_javascript_Core/runtime/WeakGCMap.h	2017-10-05 19:12:04 UTC (rev 222928)
+++ trunk/Source/_javascript_Core/runtime/WeakGCMap.h	2017-10-05 19:58:08 UTC (rev 222929)
@@ -58,6 +58,11 @@
         return m_map.set(key, WTFMove(value));
     }
 
+    AddResult add(const KeyType& key, ValueType value)
+    {
+        return m_map.add(key, WTFMove(value));
+    }
+
     bool remove(const KeyType& key)
     {
         return m_map.remove(key);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to