You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected performance penalty when using field initialiser #33698
> uname -a
Darwin Pawels-MBP-3.lan 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
> node -v
v14.3.0
@lpinca I followed the suggestion - the difference reduced to one order of magnitude, but still surprisingly large:
A_field_initialized_in_constructor x 77,519,027 ops/sec ±1.85% (90 runs sampled)
B_field_initialized_as_class_property x 6,270,322 ops/sec ±1.21% (88 runs sampled)
Test:
const{ Options, Suite }=require("benchmark");construnBenchmarkSuite=(suite)=>{returnnewPromise((resolve,reject)=>{suite.on("start",(e)=>console.log(`Running test: ${e.currentTarget.name}`)).on("cycle",(e)=>console.log(String(e.target))).on("complete",(e)=>console.log(`Fastest is ${e.currentTarget.filter("fastest").map("name")}`)).on("complete",resolve).on("error",reject).run();});};classA_field_initialized_in_constructor{constructor(){this.foo=true;}}classB_field_initialized_as_class_property{foo=true;}letinstance;runBenchmarkSuite(newSuite("fields").add("A_field_initialized_in_constructor",()=>{instance=newA_field_initialized_in_constructor();returninstance;}).add("B_field_initialized_as_class_property",()=>{instance=newB_field_initialized_as_class_property();returninstance;}));
Activity
devsnek commentedon Jun 2, 2020
Can you post a reproduction that uses only pure JavaScript?
devsnek commentedon Jun 2, 2020
@pbadenski thanks, i would recommend reporting this to https://bugs.chromium.org/p/v8/issues/list
lpinca commentedon Jun 2, 2020
I'm pretty sure this is optimized into a noop. Try to do something like this
and see if it changes the results.
pbadenski commentedon Jun 3, 2020
@lpinca I followed the suggestion - the difference reduced to one order of magnitude, but still surprisingly large:
Test:
I'll report to v8.
targos commentedon Nov 20, 2021
Closing as this should be fixed in V8. Feel free to post a link to the V8 issue if it exists.