Skip to content

let slows down performance by 5 times #5815

Description

@AlekseyMalyshev

I wrote this simple performance test recently.

There are two versions of JavaScript:

euler35/euler35.js
euler35/euler35-es6.js

The only difference is that es6 contains "use strict"; on top and uses let instead of var. This simple change however decreased ES6 performance by more than 5 times! I do not believe this should be the case. Full details are here.

  • Version: v5.9.0
  • Platform: arwin Alekseys-MBP 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64

Activity

  1. mscdex commented on Mar 20, 2016

    @mscdex
    Contributor

    This is a known issue, v8 just hasn't optimized some of the ES6 features yet. There's nothing node can really do about that.

  2. benjamingr commented on Mar 21, 2016

    @benjamingr
    Member

    V8 hasn't even optimized most of the ES5 features yet.

  3. Trott commented on Mar 21, 2016

    @Trott
    Member

    for (let...) (which is used in this example) in particular is a problem in v8 (and probably other JS engines) at this time, and should be benchmarked against for (var...) before being used in performance-critical code.

  4. Trott commented on Mar 21, 2016

    @Trott
    Member

    I'm going to close this as this is an issue that would need to be resolved on the v8 side of things. Feel free to re-open or comment if anyone feels like closing is a mistake. Also, despite being closed, feel free to comment if there are additional questions or observations.

  5. mscdex commented on Mar 21, 2016

    @mscdex
    Contributor

    FWIW there is a PR (#5819) that fixes this.

  6. Trott commented on Mar 21, 2016

    @Trott
    Member

    @mscdex Correct me if I'm mistaken, but I think that just fixes a few instances of for (let...) that are in Node.js core, but it won't make for (let...) any faster in userland code like in this issue. That will have to wait for v8 to do something awesome.

  7. AlekseyMalyshev commented on Mar 22, 2016

    @AlekseyMalyshev
    Author

    I run some tests and indeed replacing let with var in for loops significantly mitigates the issue. However a version of my test with let is still about 20% slower, than the one with var's. I think the loop somehow multiplies this delay when let it used to define the index.

  8. Trott commented on Mar 22, 2016

    @Trott
    Member

    @AlekseyMalyshev Here's the relevant issue in the v8 tracker: https://bugs.chromium.org/p/v8/issues/detail?id=4762

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

    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