Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance regression in v12 caused by primordials #29766

Closed
joyeecheung opened this issue Sep 29, 2019 · 16 comments
Closed

Performance regression in v12 caused by primordials #29766

joyeecheung opened this issue Sep 29, 2019 · 16 comments
Labels
performance Issues and PRs related to the performance of Node.js. v8 engine Issues and PRs related to the V8 dependency.

Comments

@joyeecheung
Copy link
Member

joyeecheung commented Sep 29, 2019

I have heard about performance regressions caused by transition to primordials in v12, but couldn't find a tracking issue for the regression, so opening this to make sure we are tracking it and can work with the upstream to get this handled, on way or another (feel free to close this if there is already an issue opened here).

The regressions seem to come from two types of code patterns:

  1. Calling functions through Function.prototype.{call, apply} instead of just calling them directly. There is an issue opened in the upstream by @bmeck
    https://bugs.chromium.org/p/v8/issues/detail?id=9702
  2. Looking up properties from fronzen objects - objects from our primordials namespace are frozen so lookups like const { Reflect } = primordials; Reflect.apply(...); is slower than just Reflect.apply when Reflect comes from the global object. This can be mitigated by caching the lookup results upfront, e.g. event: improve performance of EventEmitter.emit #29633 by @mcollina There is also a fairly odd tracking issue for this in the upstream: https://bugs.chromium.org/p/v8/issues/detail?id=6831

cc @MylesBorins (https://twitter.com/MylesBorins/status/1173390304742785024)

@joyeecheung joyeecheung added the performance Issues and PRs related to the performance of Node.js. label Sep 29, 2019
@targos targos added the v8 engine Issues and PRs related to the V8 dependency. label Sep 30, 2019
@mcollina
Copy link
Member

From my tests, it seems to be related to inlining.

@joyeecheung
Copy link
Member Author

I just noticed that things like primordials.Reflect are not frozen, but instead the slowdown probably comes from Object.create(null) which turns the objects into dictionary mode.

@devsnek
Copy link
Member

devsnek commented Sep 30, 2019

Can we have V8 migrate everything captured in the snapshot to fast properties?

And if all else fails... try { eval('%ToFastProperties(primordials.Reflect)') } catch {} :)

@joyeecheung
Copy link
Member Author

cc @nodejs/v8

@joyeecheung
Copy link
Member Author

For reference the primordials are baked in https://github.com/nodejs/node/blob/6ce87c0/lib/internal/per_context/primordials.js

@joyeecheung
Copy link
Member Author

One idea about the way forward: put the primordials beind a configure-time flag, and figure out how to fix the performance regression before turning it back on.

@joyeecheung
Copy link
Member Author

@nodejs/process ^ any opinions on the idea in #29766 (comment) ?

@addaleax
Copy link
Member

How much would we gain by not freezing the objects, for now? That could be put behind a flag pretty easily, right?

@joyeecheung
Copy link
Member Author

@addaleax I think we need to identify a suitable benchmark to compare the impact of removing certain bits in the primorials.js...any suggestions? (from the tweet I think @mcollina @MylesBorins @bmeck have experience on this)

@mcollina
Copy link
Member

I just did it manually, building two node versions and run some of our microbenchmarks.

@mcollina
Copy link
Member

The way how I fixed it is by just doing a simple assignment / destructuring:

const { Math, Object, Reflect } = primordials;

I would just do that everywhere, and we would be good I think.

@joyeecheung
Copy link
Member Author

joyeecheung commented Oct 22, 2019

@mcollina Thanks, that would probably be good for a code & learn task or a beginner task. I'll see if I can get this done through nodejs/code-and-learn#97 and if not, I'll spin off a separate issue about this specific task.

jizusun added a commit to jizusun/node that referenced this issue Nov 3, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Fixes: nodejs#29766
Refs: nodejs/code-and-learn#97
Refs: nodejs#29633
@jizusun
Copy link
Contributor

jizusun commented Nov 3, 2019

@joyeecheung Should i specify as Fixes: #29766 in my PR #30235. If so, I guess when my PR get merged, this issue is also closed. But what I've done is actually partial fix.

@legendecas
Copy link
Member

@jizusun Refs: https://github.com/nodejs/node/issues/29766 might make sense IMO.

ZYSzys pushed a commit that referenced this issue Nov 4, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 5, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 8, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 10, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 10, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 11, 2019
This is my first PR, and it's based on the code-and-learn guidances
This restore some performance after introducing primordialias.

Refs: #29766
Refs: nodejs/code-and-learn#97
Refs: #29633

PR-URL: #30235
Refs: #29766
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
lrecknagel added a commit to lrecknagel/node that referenced this issue Nov 12, 2019
Refs: nodejs#29766

This works on destructuring primordials whithin libs/_http_agent
gireeshpunathil pushed a commit that referenced this issue Nov 19, 2019
Refs: #29766
PR-URL: #30447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
BridgeAR pushed a commit that referenced this issue Nov 19, 2019
Refs: #29766
PR-URL: #30447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Nov 22, 2019
Refs: #29766

This works on destructuring primordials whithin libs/_http_agent

PR-URL: #30416
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Trott pushed a commit that referenced this issue Nov 23, 2019
PR-URL: #30577
Refs: nodejs/code-and-learn#97
Refs: #29766
Refs: #29633
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
targos added a commit that referenced this issue Nov 25, 2019
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

PR-URL: #30610
Refs: #29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
addaleax pushed a commit that referenced this issue Nov 30, 2019
Refs: #29766

This works on destructuring primordials whithin libs/_http_agent

PR-URL: #30416
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
addaleax pushed a commit that referenced this issue Nov 30, 2019
PR-URL: #30577
Refs: nodejs/code-and-learn#97
Refs: #29766
Refs: #29633
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
targos added a commit to targos/node that referenced this issue Nov 30, 2019
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

Backport-PR-URL: nodejs#30731
PR-URL: nodejs#30610
Refs: nodejs#29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos added a commit that referenced this issue Dec 1, 2019
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

Backport-PR-URL: #30731
PR-URL: #30610
Refs: #29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Dec 1, 2019
Refs: #29766
PR-URL: #30447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
targos pushed a commit that referenced this issue Dec 1, 2019
PR-URL: #30577
Refs: nodejs/code-and-learn#97
Refs: #29766
Refs: #29633
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
Refs: #29766
PR-URL: #30447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Dec 17, 2019
PR-URL: #30577
Refs: nodejs/code-and-learn#97
Refs: #29766
Refs: #29633
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
targos pushed a commit that referenced this issue Jan 13, 2020
Refs: #29766

This works on destructuring primordials whithin libs/_http_agent

PR-URL: #30416
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
targos added a commit that referenced this issue Jan 14, 2020
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

Backport-PR-URL: #30731
PR-URL: #30610
Refs: #29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
BethGriggs pushed a commit that referenced this issue Feb 6, 2020
Refs: #29766

This works on destructuring primordials whithin libs/_http_agent

PR-URL: #30416
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
BethGriggs pushed a commit that referenced this issue Feb 6, 2020
Store all primordials as properties of the primordials object.
Static functions are prefixed by the constructor's name and prototype
methods are prefixed by the constructor's name followed by "Prototype".
For example: primordials.Object.keys becomes primordials.ObjectKeys.

Backport-PR-URL: #30731
PR-URL: #30610
Refs: #29766
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@aduh95
Copy link
Contributor

aduh95 commented Nov 19, 2020

Both upstream issues has been closed as fixed. Should we keep this open?

@MylesBorins
Copy link
Contributor

Closing. please reopen if things are not fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Issues and PRs related to the performance of Node.js. v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

9 participants