chakra-core / chakra-core/ChakraCore

Object constructor calls are slow

Open
#3,629 4 comments 0 reactions 0 assignees View on GitHub
Performance
Dominant language
JavaScript
Stars
9.3k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

There was a discussion going on in https://github.com/webpack/webpack/issues/5600 that wraps all references into `Object ()` which was slow. v8 recently fixed it and I piggy-backed the test case from [here](http://benediktmeurer.de/2017/08/31/object-constructor-calls-in-webpack-bundles/) that was used to demonstrate v8's behavior and verified for `chakracore` and the results are similar. We are slow too and will be good to optimize to get boost in `webpack` module.

```js
const identity = x => x;

function callDirect(o) {
const foo = o.foo;
return foo(1, 2, 3);
}

function callViaCall(o) {
return o.foo.call(undefined, 1, 2, 3);
}

function callViaObject(o) {
return Object(o.foo)(1, 2, 3);
}

function callViaIdentity(o) {
return identity(o.foo)(1, 2, 3);
}

var TESTS = [
callDirect,
callViaObject,
callViaCall,
callViaIdentity
];

class A { foo(x, y, z) { return x + y + z; } };
var o = new A;
var n = 1e8;

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

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

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

Results :
```cmd
E:\git\Chakra\core>node f:\temp\object.js
callDirect: 664 ms.
callViaObject: 1906 ms.
callViaCall: 329 ms.
callViaIdentity: 454 ms.

E:\git\Chakra\core>node -pe "process.versions"
{ http_parser: '2.7.0',
node: '8.4.0',
chakracore: '1.7.1.0',
uv: '1.13.1',
zlib: '1.2.11',
ares: '1.10.1-DEV',
modules: '57',
nghttp2: '1.22.0',
openssl: '1.0.2l',
icu: '59.1',
unicode: '9.0',
cldr: '31.0.1',
tz: '2017b' }
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.