Title: [252464] trunk
Revision
252464
Author
commit-qu...@webkit.org
Date
2019-11-14 13:59:58 -0800 (Thu, 14 Nov 2019)

Log Message

Use toLength() and getIndexQuickly() in JSON.stringify
https://bugs.webkit.org/show_bug.cgi?id=204122

Patch by Alexey Shvayka <shvaikal...@gmail.com> on 2019-11-14
Reviewed by Yusuke Suzuki.

JSTests:

* microbenchmarks/json-stringify-array-replacer.js: Added.
* microbenchmarks/json-stringify-empty-array.js: Added.

Source/_javascript_Core:

Using toLength() is semantically equivalent and performance-neutral, while adding
JSObject::getIndexQuickly() advances microbenchmarks/json-stringify-array-replacer.js
by 34%.

* runtime/JSONObject.cpp:
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::Holder::appendNextProperty):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (252463 => 252464)


--- trunk/JSTests/ChangeLog	2019-11-14 20:51:03 UTC (rev 252463)
+++ trunk/JSTests/ChangeLog	2019-11-14 21:59:58 UTC (rev 252464)
@@ -1,3 +1,13 @@
+2019-11-14  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        Use toLength() and getIndexQuickly() in JSON.stringify
+        https://bugs.webkit.org/show_bug.cgi?id=204122
+
+        Reviewed by Yusuke Suzuki.
+
+        * microbenchmarks/json-stringify-array-replacer.js: Added.
+        * microbenchmarks/json-stringify-empty-array.js: Added.
+
 2019-11-14  Caio Lima  <ticaiol...@gmail.com>
 
         Support or16(TrustedImm32, AbsoluteAddress) in the MIPS MacroAssembler

Added: trunk/JSTests/microbenchmarks/json-stringify-array-replacer.js (0 => 252464)


--- trunk/JSTests/microbenchmarks/json-stringify-array-replacer.js	                        (rev 0)
+++ trunk/JSTests/microbenchmarks/json-stringify-array-replacer.js	2019-11-14 21:59:58 UTC (rev 252464)
@@ -0,0 +1,3 @@
+const replacer = new Array(15).fill('key');
+for (let i = 0; i < 1e6; ++i)
+    JSON.stringify(null, replacer);

Added: trunk/JSTests/microbenchmarks/json-stringify-empty-array.js (0 => 252464)


--- trunk/JSTests/microbenchmarks/json-stringify-empty-array.js	                        (rev 0)
+++ trunk/JSTests/microbenchmarks/json-stringify-empty-array.js	2019-11-14 21:59:58 UTC (rev 252464)
@@ -0,0 +1,3 @@
+const arr = [];
+for (let i = 0; i < 1e6; ++i)
+    JSON.stringify(arr);

Modified: trunk/Source/_javascript_Core/ChangeLog (252463 => 252464)


--- trunk/Source/_javascript_Core/ChangeLog	2019-11-14 20:51:03 UTC (rev 252463)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-11-14 21:59:58 UTC (rev 252464)
@@ -1,3 +1,18 @@
+2019-11-14  Alexey Shvayka  <shvaikal...@gmail.com>
+
+        Use toLength() and getIndexQuickly() in JSON.stringify
+        https://bugs.webkit.org/show_bug.cgi?id=204122
+
+        Reviewed by Yusuke Suzuki.
+
+        Using toLength() is semantically equivalent and performance-neutral, while adding
+        JSObject::getIndexQuickly() advances microbenchmarks/json-stringify-array-replacer.js
+        by 34%.
+
+        * runtime/JSONObject.cpp:
+        (JSC::Stringifier::Stringifier):
+        (JSC::Stringifier::Holder::appendNextProperty):
+
 2019-11-14  Caio Lima  <ticaiol...@gmail.com>
 
         Support or16(TrustedImm32, AbsoluteAddress) in the MIPS MacroAssembler

Modified: trunk/Source/_javascript_Core/runtime/JSONObject.cpp (252463 => 252464)


--- trunk/Source/_javascript_Core/runtime/JSONObject.cpp	2019-11-14 20:51:03 UTC (rev 252463)
+++ trunk/Source/_javascript_Core/runtime/JSONObject.cpp	2019-11-14 21:59:58 UTC (rev 252464)
@@ -237,13 +237,16 @@
             RETURN_IF_EXCEPTION(scope, );
             if (isArrayReplacer) {
                 m_usingArrayReplacer = true;
-                JSValue lengthValue = replacerObject->get(globalObject, vm.propertyNames->length);
+                unsigned length = toLength(globalObject, replacerObject);
                 RETURN_IF_EXCEPTION(scope, );
-                unsigned length = lengthValue.toUInt32(globalObject);
-                RETURN_IF_EXCEPTION(scope, );
-                for (unsigned i = 0; i < length; ++i) {
-                    JSValue name = replacerObject->get(globalObject, i);
-                    RETURN_IF_EXCEPTION(scope, );
+                for (unsigned index = 0; index < length; ++index) {
+                    JSValue name;
+                    if (isJSArray(replacerObject) && replacerObject->canGetIndexQuickly(index))
+                        name = replacerObject->getIndexQuickly(index);
+                    else {
+                        name = replacerObject->get(globalObject, index);
+                        RETURN_IF_EXCEPTION(scope, );
+                    }
                     if (name.isObject()) {
                         auto* nameObject = jsCast<JSObject*>(name);
                         if (!nameObject->inherits<NumberObject>(vm) && !nameObject->inherits<StringObject>(vm))
@@ -486,14 +489,8 @@
     // First time through, initialize.
     if (!m_index) {
         if (m_isArray) {
-            if (m_isJSArray)
-                m_size = asArray(m_object)->length();
-            else {
-                JSValue value = m_object->get(globalObject, vm.propertyNames->length);
-                RETURN_IF_EXCEPTION(scope, false);
-                m_size = value.toUInt32(globalObject);
-                RETURN_IF_EXCEPTION(scope, false);
-            }
+            m_size = toLength(globalObject, m_object);
+            RETURN_IF_EXCEPTION(scope, false);
             builder.append('[');
         } else {
             if (stringifier.m_usingArrayReplacer)
@@ -528,8 +525,8 @@
     if (m_isArray) {
         // Get the value.
         JSValue value;
-        if (m_isJSArray && asArray(m_object)->canGetIndexQuickly(index))
-            value = asArray(m_object)->getIndexQuickly(index);
+        if (m_isJSArray && m_object->canGetIndexQuickly(index))
+            value = m_object->getIndexQuickly(index);
         else {
             PropertySlot slot(m_object, PropertySlot::InternalMethodType::Get);
             bool hasProperty = m_object->getPropertySlot(globalObject, index, slot);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to