Skip to content

Unexpected performance penalty when using field initialiser #33698

Closed
@pbadenski

Description

@pbadenski

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions