镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Performance regression in v12 caused by primordials #29766

Description

@joyeecheung

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)

Activity

  1. added
    performanceIssues and PRs related to the performance of Node.js.
    on Sep 29, 2019
  2. added
    v8 engineIssues and PRs related to the V8 dependency.
    on Sep 30, 2019
  3. mcollina commented on Sep 30, 2019

    @mcollina
    SponsorMember

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

  4. joyeecheung commented on Sep 30, 2019

    @joyeecheung
    MemberAuthor

    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.

  5. devsnek commented on Sep 30, 2019

    @devsnek
    Member

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

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

  6. joyeecheung commented on Sep 30, 2019

    @joyeecheung
    MemberAuthor

    cc @nodejs/v8

  7. joyeecheung commented on Sep 30, 2019

    @joyeecheung
    MemberAuthor
  8. joyeecheung commented on Oct 10, 2019

    @joyeecheung
    MemberAuthor

    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.

  9. joyeecheung commented on Oct 10, 2019

    @joyeecheung
    MemberAuthor

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

  10. addaleax commented on Oct 10, 2019

    @addaleax
    Member

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

  11. joyeecheung commented on Oct 11, 2019

    @joyeecheung
    MemberAuthor

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

  12. mcollina commented on Oct 11, 2019

    @mcollina
    SponsorMember

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

  13. mcollina commented on Oct 15, 2019

    @mcollina
    SponsorMember

    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.

  14. joyeecheung commented on Oct 22, 2019

    @joyeecheung
    MemberAuthor

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

  15. 19 remaining items

  16. aduh95 commented on Nov 19, 2020

    @aduh95
    Contributor

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

  17. MylesBorins commented on Nov 19, 2020

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssues and PRs related to the performance of Node.js.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