Issue 5988 in v8: Optimize Object.assign

252 views
Skip to first unread message

bmeu… via monorail

unread,
Feb 20, 2017, 12:24:04 AM2/20/17
to v8-re...@googlegroups.com
Status: Available
Owner: verwa...@chromium.org
CC: bmeu...@chromium.org, mvstan...@chromium.org, cbr...@chromium.org, da...@chromium.org
Labels: Performance Harmony HelpWanted TurboFan
Components: Runtime

New issue 5988 by bmeu...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988

The Object.assign builtin introduced with ES2015 is fairly popular today because Babel uses it as polyfill for spread properties, which in turn are used quite often in Redux/React applications nowadays. For example

function foo(a) {
return {...a}
}

is transpiled to

"use strict";

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function foo(a) {
return _extends({}, a);
}

by Babel. Currently Object.assign is kinda naive, but we could apply the same tricks that we used for JSON.parse to speed it up for this (common) case.

In TurboFan we could also recognize the case of Object.assign({}, a) specifically and lower to a call to an optimized stub.

--
You received this message because:
1. The project was configured to send all issue notifications to this address

You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings

bmeu… via monorail

unread,
Feb 20, 2017, 12:28:55 AM2/20/17
to v8-re...@googlegroups.com
Issue 5988: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988

This issue is now blocking issue 5989.
See https://bugs.chromium.org/p/v8/issues/detail?id=5989

sathv… via monorail

unread,
Aug 21, 2017, 7:45:35 PM8/21/17
to v8-re...@googlegroups.com

Comment #4 on issue 5988 by sathv...@gmail.com: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c4

Do you think this would be a good target to dive into TF/v8 internals ?
I could take a look at this issue/

bmeu… via monorail

unread,
Aug 22, 2017, 12:41:27 PM8/22/17
to v8-re...@googlegroups.com

Comment #5 on issue 5988 by bmeu...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c5

It's fairly complicated and probably not a good starter project. Esp. not for diving into TF (or the CodeStubAssembler).

bmeu… via monorail

unread,
Oct 10, 2017, 4:17:36 AM10/10/17
to v8-re...@googlegroups.com
Updates:
Labels: Hotlist-NodeJS

Comment #6 on issue 5988 by bmeu...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c6

According to https://github.com/nodejs/node/pull/16081#pullrequestreview-68136151 the hand-rolled Object.keys based util._extend() still beats the shit out of Object.assign even for the simple case, i.e. nothing fancy, just:

================< bench-object-assign.js >==================================
if (typeof console === 'undefined') console = {log:print};

const N = 1e6;
const TESTS = [];

(function() {
const options = {a:1, b:'2', c:null, d:0.1};
function _extend(target, source) {
// Don't do anything if source isn't an object
if (source === null || typeof source !== 'object') return target;
var keys = Object.keys(source);
var i = keys.length;
while (i--) {
target[keys[i]] = source[keys[i]];
}
return target;
}

TESTS.push(
function objectAssignEmpty() {
return Object.assign({}, options);
},
function utilExtendEmpty() {
return _extend({}, options);
});
})();

function test(fn) {
var result;
for (var i = 0; i < N; i += 1) result = fn();
return result;
}

test(x => x);

for (var j = 0; j < TESTS.length; ++j) {
test(TESTS[j]);
}

for (var j = 0; j < TESTS.length; ++j) {
var startTime = Date.now();
test(TESTS[j]);
console.log(TESTS[j].name + ':', (Date.now() - startTime), 'ms.');
}
============================================================================

On V8 ToT this shows a significant performance penalty for using Object.assign:

============================================================================
$ out/Release/d8 bench-object-assign.js
objectAssignEmpty: 528 ms.
utilExtendEmpty: 158 ms.
============================================================================

Given that this is not only an issue for Node, but as mentioned above this is used heavily in many React projects via Babel, we should probably try to do something about it soon.

Toon you mentioned a couple of times that you have ideas how to improve performance of Object.assign. Can you share those ideas on this bug?

cbr… via monorail

unread,
Oct 10, 2017, 4:28:02 AM10/10/17
to v8-re...@googlegroups.com

Comment #7 on issue 5988 by cbr...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c7

No hurry, it's on our plate.

math… via monorail

unread,
Feb 2, 2018, 1:28:55 PM2/2/18
to v8-re...@googlegroups.com
Updates:
Labels: Hotlist-Speedometer

Comment #9 on issue 5988 by mat...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c9

(No comment was entered for this change.)

cbr… via monorail

unread,
Feb 5, 2018, 6:52:04 AM2/5/18
to v8-re...@googlegroups.com
Updates:
Owner: ish...@chromium.org

Comment #10 on issue 5988 by cbr...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c10

Igor is "officially" signed up for this project :)

bugdro… via monorail

unread,
Mar 1, 2018, 10:59:01 AM3/1/18
to v8-re...@googlegroups.com

Comment #11 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c11

The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6

commit 40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6
Author: Igor Sheludko <ish...@chromium.org>
Date: Thu Mar 01 15:58:16 2018

[runtime] Move validity cell from PrototypeInfo to Map.

This is a first step towards using Maps as store transition handlers.
It is expected for this CL to noticeably regress memory consumption
but most of it should be recovered by the next CL.

Bug: v8:5988
Change-Id: Ic2e301f9ccebc36e699383ded8c8cd284a906ce1
Reviewed-on: https://chromium-review.googlesource.com/928646
Commit-Queue: Igor Sheludko <ish...@chromium.org>
Reviewed-by: Camillo Bruni <cbr...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51663}
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/factory.cc
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/heap/heap.cc
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects-debug.cc
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects-inl.h
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects-printer.cc
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects.cc
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects.h
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects/map-inl.h
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/src/objects/map.h
[modify] https://crrev.com/40a3e6dcb9bdb5cb2a7f6e29fa8e4de75e538ef6/tools/v8heapconst.py

bugdro… via monorail

unread,
Mar 8, 2018, 5:41:29 AM3/8/18
to v8-re...@googlegroups.com

Comment #12 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c12


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/aeee606360932b95dec2ec4fdfd4b27c5f49a111

commit aeee606360932b95dec2ec4fdfd4b27c5f49a111
Author: Igor Sheludko <ish...@chromium.org>
Date: Thu Mar 08 10:40:55 2018

[ic] Introduce canonical invalid prototype validity cell.

... and use Smi Map::kPrototypeChainValid for the cases where direct receiver's
prototype is not JSObject instead of creating a new valid cell for each such
case. This will make a validity cell checking code simpler.

Bug: v8:5988
Change-Id: I52cf55797171cc8021d80e4e441615d0c8fc8bd4
Reviewed-on: https://chromium-review.googlesource.com/951384

Commit-Queue: Igor Sheludko <ish...@chromium.org>
Reviewed-by: Camillo Bruni <cbr...@chromium.org>
Reviewed-by: Ulan Degenbaev <ul...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51803}
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/heap/heap.cc
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/heap/heap.h
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/heap/setup-heap-internal.cc
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/ic/accessor-assembler.cc
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/ic/accessor-assembler.h
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/ic/handler-configuration.cc
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/src/objects.cc
[modify] https://crrev.com/aeee606360932b95dec2ec4fdfd4b27c5f49a111/tools/v8heapconst.py

ish… via monorail

unread,
Mar 13, 2018, 10:11:37 AM3/13/18
to v8-re...@googlegroups.com
Updates:
Status: Started

Comment #13 on issue 5988 by ish...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c13


(No comment was entered for this change.)

bugdro… via monorail

unread,
Mar 23, 2018, 2:58:36 PM3/23/18
to v8-re...@googlegroups.com

Comment #14 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c14


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/78c6bbd930b9138002cfb52642b90b9aab104a78

commit 78c6bbd930b9138002cfb52642b90b9aab104a78
Author: Igor Sheludko <ish...@chromium.org>
Date: Fri Mar 23 15:37:40 2018

[ic] Use Map as transition handlers instead of StoreHandler objects.

This eases transition handlers caching and avoids memory overhead of
respective StoreHandler objects. In addition, it allows to use such
transition handlers on runtime side to make Object.assign implementation
a bit faster.

Bug: v8:5988
Change-Id: Iba660a11d4b300cd5f80615fb7e2608e53da8fee
Reviewed-on: https://chromium-review.googlesource.com/931701
Reviewed-by: Toon Verwaest <verw...@chromium.org>
Commit-Queue: Igor Sheludko <ish...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52187}
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/builtins/builtins-internal-gen.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/code-stub-assembler.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/accessor-assembler.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/accessor-assembler.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/handler-configuration-inl.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/handler-configuration.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/handler-configuration.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/ic.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/ic.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/ic/keyed-store-generic.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/lookup.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/lookup.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/objects.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/objects/descriptor-array.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/objects/map-inl.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/objects/map.h
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/transitions.cc
[modify] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/src/transitions.h
[add] https://crrev.com/78c6bbd930b9138002cfb52642b90b9aab104a78/test/mjsunit/regress/regress-store-transition-dict.js

bugdro… via monorail

unread,
Apr 4, 2018, 7:56:47 AM4/4/18
to v8-re...@googlegroups.com

Comment #15 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c15


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/139fe2db1c150e09f68499d75698a00839770fa5

commit 139fe2db1c150e09f68499d75698a00839770fa5
Author: Igor Sheludko <ish...@chromium.org>
Date: Wed Apr 04 11:56:21 2018

[ic] Implement TransitionArray lookup in CSA.

Drive-by cleanup: remove megamorphic stub cache lookup support from generic property
store code. This lookup is no longer necessary because
1) fast stores to existing properties get all the information from the map,
2) transitioning store targets are taken directly from the transition array,
so in both cases there's no point in doing a store handler lookup.

Bug: v8:5988
Change-Id: I95c0a08e7d1a76bb0f4475a9bd685e4e11e16a48
Reviewed-on: https://chromium-review.googlesource.com/983921

Commit-Queue: Igor Sheludko <ish...@chromium.org>
Reviewed-by: Camillo Bruni <cbr...@chromium.org>

bugdro… via monorail

unread,
Apr 4, 2018, 1:01:31 PM4/4/18
to v8-re...@googlegroups.com

Comment #16 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c16


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/b6021b983db7f1f21688e75347fa2ca6b81aff29

commit b6021b983db7f1f21688e75347fa2ca6b81aff29
Author: Igor Sheludko <ish...@chromium.org>
Date: Wed Apr 04 17:00:50 2018

[runtime] Make Map::GetOrCreatePrototypeChainValidityCell() return smi instead of empty handle.

Bug: v8:5988
Change-Id: I6f62199f062ea32e66903f5385fc109e47fed374
Reviewed-on: https://chromium-review.googlesource.com/970822

Commit-Queue: Igor Sheludko <ish...@chromium.org>
Reviewed-by: Camillo Bruni <cbr...@chromium.org>

bugdro… via monorail

unread,
Apr 5, 2018, 8:27:43 AM4/5/18
to v8-re...@googlegroups.com

Comment #17 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c17


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/844b762f53e0e8fbfcf9985790953ceff0fe2f27

commit 844b762f53e0e8fbfcf9985790953ceff0fe2f27
Author: Igor Sheludko <ish...@chromium.org>
Date: Thu Apr 05 12:27:26 2018

[ic][runtime] Don't use LookupIterator::ForTransitionHandler() constructor.

It looks like the normal ways of creating lookup iterators work better.

Bug: v8:5988, chromium:828282
Change-Id: Ifd623b2e93708ff8684d056d9292b7779f611a3c
Reviewed-on: https://chromium-review.googlesource.com/997474
Reviewed-by: Camillo Bruni <cbr...@chromium.org>
Commit-Queue: Igor Sheludko <ish...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52392}
[modify] https://crrev.com/844b762f53e0e8fbfcf9985790953ceff0fe2f27/src/ic/ic.cc
[modify] https://crrev.com/844b762f53e0e8fbfcf9985790953ceff0fe2f27/src/lookup.cc
[modify] https://crrev.com/844b762f53e0e8fbfcf9985790953ceff0fe2f27/src/objects.cc

bugdro… via monorail

unread,
Apr 6, 2018, 9:17:42 AM4/6/18
to v8-re...@googlegroups.com

Comment #18 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c18


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/d1532a1aef5b841da0ab507e5deb5b522a5bb0a2

commit d1532a1aef5b841da0ab507e5deb5b522a5bb0a2
Author: Igor Sheludko <ish...@chromium.org>
Date: Fri Apr 06 13:17:07 2018

[ic] Don't use slow stub handler for fresh transitioning stores.

Given that we got a store transition handler for free (because it's just
a transition map) there's no need to wait for a second "use" of that
transition in order to install a normal store transition handler.

Bug: v8:5988
Change-Id: Iecdcfdd096a8efffdd0662f1b1d604943e57d85a
Reviewed-on: https://chromium-review.googlesource.com/997553

Reviewed-by: Camillo Bruni <cbr...@chromium.org>
Commit-Queue: Igor Sheludko <ish...@chromium.org>

bugdro… via monorail

unread,
Apr 6, 2018, 10:26:27 AM4/6/18
to v8-re...@googlegroups.com

Comment #19 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c19


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a

commit e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a
Author: Igor Sheludko <ish...@chromium.org>
Date: Fri Apr 06 14:25:34 2018

[csa] Minor refactoring to prepare for the Object.assign CL.

1) Add exit point parameter to EmitGenericPropertyStore(),
2) carve TryLookupPropertyInSimpleObject() out of TryLookupProperty().

Bug: v8:5988
Change-Id: I6cef48731c27e5bb72dce5eaa0169fbf59787ed7
Reviewed-on: https://chromium-review.googlesource.com/997747
Reviewed-by: Marja Hölttä <ma...@chromium.org>
Commit-Queue: Igor Sheludko <ish...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52448}
[modify] https://crrev.com/e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a/src/code-stub-assembler.cc
[modify] https://crrev.com/e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a/src/code-stub-assembler.h
[modify] https://crrev.com/e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a/src/ic/accessor-assembler.cc
[modify] https://crrev.com/e4a72d8b7f1f0ee89a70696c4409e1a08fc9623a/src/ic/keyed-store-generic.cc

bugdro… via monorail

unread,
Apr 15, 2018, 10:07:37 PM4/15/18
to v8-re...@googlegroups.com

Comment #20 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c20


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/9367f80f17237a031c1677e9d358cb1df4e6c01c

commit 9367f80f17237a031c1677e9d358cb1df4e6c01c
Author: Igor Sheludko <ish...@chromium.org>
Date: Mon Apr 16 02:06:46 2018

[builtins] Implement fast path of Object.assign using CSA.

Bug: v8:5988
Change-Id: I2e90ed8df6b966e04299774e50aeb2913a8c1922
Reviewed-on: https://chromium-review.googlesource.com/999603
Commit-Queue: Igor Sheludko <ish...@chromium.org>
Reviewed-by: Toon Verwaest <verw...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52610}
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/builtins/builtins-definitions.h
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/builtins/builtins-object-gen.cc
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/builtins/builtins-object.cc
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/code-stub-assembler.cc
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/code-stub-assembler.h
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/ic/keyed-store-generic.cc
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/ic/keyed-store-generic.h
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/runtime/runtime-object.cc
[modify] https://crrev.com/9367f80f17237a031c1677e9d358cb1df4e6c01c/src/runtime/runtime.h

bugdro… via monorail

unread,
Apr 18, 2018, 3:23:09 AM4/18/18
to v8-re...@googlegroups.com

Comment #21 on issue 5988 by bugd...@chromium.org: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c21


The following revision refers to this bug:
https://chromium.googlesource.com/v8/v8.git/+/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce

commit e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce
Author: Marja Hölttä <ma...@chromium.org>
Date: Wed Apr 18 07:21:25 2018

[cleanup] Remove dead TransitionAccessor::Encoding::kHandler + related code.

This is also pre-work for in-place weak refs.

BUG=v8:7308, v8:5988

Change-Id: Ie78b0c59695c1e6af9780fffb363c931e2ee34e2
Reviewed-on: https://chromium-review.googlesource.com/1013583
Commit-Queue: Marja Hölttä <ma...@chromium.org>
Reviewed-by: Igor Sheludko <ish...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52658}
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/ic/handler-configuration-inl.h
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/ic/handler-configuration.cc
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/ic/handler-configuration.h
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/objects-printer.cc
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/transitions-inl.h
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/transitions.cc
[modify] https://crrev.com/e784719b4ff7c2cc6aa2d7ad5ba95eb7413513ce/src/transitions.h

a.r.brid… via monorail

unread,
Dec 17, 2018, 10:32:59 PM12/17/18
to v8-re...@googlegroups.com

Comment #22 on issue 5988 by a.r.brid...@googlemail.com: Optimize Object.assign
https://bugs.chromium.org/p/v8/issues/detail?id=5988#c22

It seems like the fast path for Object.assign does not work for objects with number properties. In that case it always hits the slow path while AFAIK it should be possible to use a fast path.

Comparing the results with e.g., object spread and a hand written primitive assign function on the latest V8 version:

./out/x64.release/d8 ../../node/t.js
assign (19): 3973 ms.
assign (20): 4031 ms.
_extend (19): 1073 ms.
_extend (20): 1110 ms.
spread (19): 105 ms.
spread (20): 98 ms.
assign (19): 3915 ms.
assign (20): 4094 ms.
_extend (19): 1060 ms.
_extend (20): 1094 ms.
spread (19): 97 ms.
spread (20): 98 ms.

The code:

```js
'use strict';

function assign(source) {
return Object.assign({}, source);
}

function _extend(source) {
const target = {};
const keys = Object.keys(source);
let i = keys.length;

while (i--) {
target[keys[i]] = source[keys[i]];
}
return target;
}

function spread(source) {
return { ...source };
}

function bench(fn, max) {
const src = {};
for (let n = 0; n < max; n++)
src[`${n}`] = n;

const start = Date.now();
let count = 0;
for (let i = 0; i < 1e6; i++) {
src[`${i % max}`] = i * 2;
count += fn(src)[`${(i + 1) % max}`];
}
console.log(`${fn.name} (${max}): ${Date.now() - start} ms.`);
return count;
}

for (let i = 0; i < 2; i++) {
bench(assign, 19);
bench(assign, 20);
bench(_extend, 19);
bench(_extend, 20);
bench(spread, 19);
bench(spread, 20);
}
```
Reply all
Reply to author
Forward
0 new messages