Issue 12242 in v8: Slow class initialization with class members

64 views
Skip to first unread message

ro… via monorail

unread,
Sep 18, 2021, 12:06:21 PM9/18/21
to v8-re...@googlegroups.com
Status: Untriaged
Owner: ----
Type: Bug

New issue 12242 by ro...@foxglove.dev: Slow class initialization with class members
https://bugs.chromium.org/p/v8/issues/detail?id=12242

Version: 93.0.4577.82 (Official Build) (arm64)
OS: macOS 11.5.2
Architecture: arm64
JavaScript: V8 9.3.345.19

What steps will reproduce the problem?

I created the following code in a <script> tag on an otherwise empty page:

```
class WithMember {
x;
}

class WithConstructor {
constructor() {
this.x = undefined;
}
}

new WithMember();
new WithConstructor();

function runWithMember() {
for (let i=0; i<1000000 ; ++i) {
new WithMember();
}
}

function runWithConstructor() {
for (let i=0; i<1000000 ; ++i) {
new WithConstructor();
}
}

runWithMember();
runWithConstructor();
```

When I run the above and capture the performance with the "performance" tab in Devtools - I see that the "runWithMember" version runs significantly slower (close to 100x slower) due to "<instance_members_initializer>"


What is the expected output?

I would expect both versions to have the same runtime.

I've attached a screenshot of the performance tab showing the discrepancy in runtime.

Should I be doing something differently in the `WithMember` version?

P.S. - I've also tried `#x;` and `#x = undefined`; in the `WithMember` class both leading to the same runtime result as just `x;`

Attachments:
Screen Shot 2021-09-18 at 9.03.08 AM.png 228 KB

--
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

s… via monorail

unread,
Sep 23, 2021, 7:48:33 PM9/23/21
to v8-re...@googlegroups.com
Updates:
Mergedinto: 9888
Status: Duplicate

Comment #1 on issue 12242 by s...@chromium.org: Slow class initialization with class members
https://bugs.chromium.org/p/v8/issues/detail?id=12242#c1

Hi Roman, thanks for the report. This is a known performance gap between public class fields and properties that is being worked on. Deduplicating.

ro… via monorail

unread,
Oct 9, 2021, 10:36:37 AM10/9/21
to v8-re...@googlegroups.com

Comment #2 on issue 12242 by ro...@foxglove.dev: Slow class initialization with class members
https://bugs.chromium.org/p/v8/issues/detail?id=12242#c2

Thanks for referencing the other ticket. Any thoughts on if #9888 is scheduled to have someone look at it and fix or if lots of research remains to identify a workable fix?
Reply all
Reply to author
Forward
0 new messages