Title: [218790] trunk
Revision
218790
Author
[email protected]
Date
2017-06-24 15:29:22 -0700 (Sat, 24 Jun 2017)

Log Message

[JSC] Clean up Object.entries implementation
https://bugs.webkit.org/show_bug.cgi?id=173759

Reviewed by Sam Weinig.

JSTests:

* microbenchmarks/object-entries.js: Added.
(test):

Source/_javascript_Core:

This patch cleans up Object.entries implementation.
We drop unused private functions. And we merge the
implementation into Object.entries.

It slightly speeds up Object.entries speed.

                             baseline                  patched

    object-entries      148.0101+-5.6627          142.1877+-4.8661          might be 1.0409x faster

* builtins/BuiltinNames.h:
* builtins/ObjectConstructor.js:
(entries):
(globalPrivate.enumerableOwnProperties): Deleted.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* runtime/ObjectConstructor.cpp:
(JSC::ownEnumerablePropertyKeys): Deleted.
* runtime/ObjectConstructor.h:

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (218789 => 218790)


--- trunk/JSTests/ChangeLog	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/JSTests/ChangeLog	2017-06-24 22:29:22 UTC (rev 218790)
@@ -1,3 +1,13 @@
+2017-06-24  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Clean up Object.entries implementation
+        https://bugs.webkit.org/show_bug.cgi?id=173759
+
+        Reviewed by Sam Weinig.
+
+        * microbenchmarks/object-entries.js: Added.
+        (test):
+
 2017-06-24  Joseph Pecoraro  <[email protected]>
 
         Remove Reflect.enumerate

Added: trunk/JSTests/microbenchmarks/object-entries.js (0 => 218790)


--- trunk/JSTests/microbenchmarks/object-entries.js	                        (rev 0)
+++ trunk/JSTests/microbenchmarks/object-entries.js	2017-06-24 22:29:22 UTC (rev 218790)
@@ -0,0 +1,13 @@
+var object = {};
+for (var i = 0; i < 1e3; ++i) {
+    object[i + 'prop'] = i;
+}
+
+function test(object)
+{
+    return Object.entries(object);
+}
+noInline(test);
+
+for (var i = 0; i < 1e3; ++i)
+    test(object);

Modified: trunk/Source/_javascript_Core/ChangeLog (218789 => 218790)


--- trunk/Source/_javascript_Core/ChangeLog	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-06-24 22:29:22 UTC (rev 218790)
@@ -1,3 +1,31 @@
+2017-06-24  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Clean up Object.entries implementation
+        https://bugs.webkit.org/show_bug.cgi?id=173759
+
+        Reviewed by Sam Weinig.
+
+        This patch cleans up Object.entries implementation.
+        We drop unused private functions. And we merge the
+        implementation into Object.entries.
+
+        It slightly speeds up Object.entries speed.
+
+                                     baseline                  patched
+
+            object-entries      148.0101+-5.6627          142.1877+-4.8661          might be 1.0409x faster
+
+
+        * builtins/BuiltinNames.h:
+        * builtins/ObjectConstructor.js:
+        (entries):
+        (globalPrivate.enumerableOwnProperties): Deleted.
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        * runtime/ObjectConstructor.cpp:
+        (JSC::ownEnumerablePropertyKeys): Deleted.
+        * runtime/ObjectConstructor.h:
+
 2017-06-24  Joseph Pecoraro  <[email protected]>
 
         Remove Reflect.enumerate

Modified: trunk/Source/_javascript_Core/builtins/BuiltinNames.h (218789 => 218790)


--- trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2017-06-24 22:29:22 UTC (rev 218790)
@@ -52,7 +52,6 @@
     macro(deferred) \
     macro(countdownHolder) \
     macro(Object) \
-    macro(ownEnumerablePropertyKeys) \
     macro(Number) \
     macro(Array) \
     macro(ArrayBuffer) \

Modified: trunk/Source/_javascript_Core/builtins/ObjectConstructor.js (218789 => 218790)


--- trunk/Source/_javascript_Core/builtins/ObjectConstructor.js	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/builtins/ObjectConstructor.js	2017-06-24 22:29:22 UTC (rev 218790)
@@ -24,35 +24,21 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-@globalPrivate
-function enumerableOwnProperties(object, kind)
+function entries(object)
 {
     "use strict";
 
-    const obj = @Object(object);
-    const ownKeys = @Reflect.@ownKeys(obj);
-    const properties = [];
-    for (let i = 0, keysLength = ownKeys.length; i < keysLength; ++i) {
-        let nextKey = ownKeys[i];
-        if (typeof nextKey === 'string') {
-            if (@propertyIsEnumerable(obj, nextKey)) {
-                if (kind === @iterationKindValue)
-                    properties.@push(obj[nextKey]);
-                else if (kind === @iterationKindKeyValue)
-                    properties.@push([nextKey, obj[nextKey]]);
-            }
-        }
+    if (object == null)
+        @throwTypeError("Object.entries requires that input parameter not be null or undefined");
+
+    var obj = @Object(object);
+    var names = @getOwnPropertyNames(obj);
+    var properties = [];
+    for (var i = 0, length = names.length; i < length; ++i) {
+        var name = names[i];
+        if (@propertyIsEnumerable(obj, name))
+            properties.@push([name, obj[name]]);
     }
-    
+
     return properties;
 }
-
-function entries(object)
-{
-    "use strict";
-    
-    if (object == null)
-        @throwTypeError("Object.entries requires that input parameter not be null or undefined");
-    
-    return @enumerableOwnProperties(object, @iterationKindKeyValue);
-}

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (218789 => 218790)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2017-06-24 22:29:22 UTC (rev 218790)
@@ -725,6 +725,7 @@
     JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
     JSFunction* privateFuncTrunc = JSFunction::create(vm, this, 0, String(), mathProtoFuncTrunc, TruncIntrinsic);
 
+    JSFunction* privateFuncGetOwnPropertyNames = JSFunction::create(vm, this, 0, String(), objectConstructorGetOwnPropertyNames);
     JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
     JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
@@ -777,7 +778,7 @@
         GlobalPropertyInfo(vm.propertyNames->NaN, jsNaN(), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->Infinity, jsNumber(std::numeric_limits<double>::infinity()), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->undefinedKeyword, jsUndefined(), DontEnum | DontDelete | ReadOnly),
-        GlobalPropertyInfo(vm.propertyNames->builtinNames().ownEnumerablePropertyKeysPrivateName(), JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->builtinNames().getOwnPropertyNamesPrivateName(), privateFuncGetOwnPropertyNames, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly),

Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp (218789 => 218790)


--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2017-06-24 22:29:22 UTC (rev 218790)
@@ -297,16 +297,6 @@
     return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::Strings, DontEnumPropertiesMode::Exclude));
 }
 
-EncodedJSValue JSC_HOST_CALL ownEnumerablePropertyKeys(ExecState* exec)
-{
-    VM& vm = exec->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    JSObject* object = exec->argument(0).toObject(exec);
-    RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    scope.release();
-    return JSValue::encode(ownPropertyKeys(exec, object, PropertyNameMode::StringsAndSymbols, DontEnumPropertiesMode::Exclude));
-}
-
 EncodedJSValue JSC_HOST_CALL objectConstructorAssign(ExecState* exec)
 {
     VM& vm = exec->vm();

Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.h (218789 => 218790)


--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.h	2017-06-24 21:47:37 UTC (rev 218789)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.h	2017-06-24 22:29:22 UTC (rev 218790)
@@ -29,8 +29,8 @@
 EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptor(ExecState*);
 EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyDescriptors(ExecState*);
 EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertySymbols(ExecState*);
+EncodedJSValue JSC_HOST_CALL objectConstructorGetOwnPropertyNames(ExecState*);
 EncodedJSValue JSC_HOST_CALL objectConstructorKeys(ExecState*);
-EncodedJSValue JSC_HOST_CALL ownEnumerablePropertyKeys(ExecState*);
 
 class ObjectPrototype;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to