Closed
Description
I'm getting 2 orders of magnitude performance penalty when using field initialiser. See snippet below (corrected after @devsnek comment):
"use strict";
class A_field_initialized_in_constructor {
constructor() {
this.foo = true;
}
}
class B_field_initialized_as_class_property {
foo = true;
}
and the results (using https://www.npmjs.com/package/benchmark):
A_field_initialized_in_constructor x 812,776,791 ops/sec ±0.94% (91 runs sampled)
B_field_initialized_as_class_property x 5,935,129 ops/sec ±2.31% (86 runs sampled)
Environment:
> 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