Repository navigation
let slows down performance by 5 times #5815
Description
Activity
- addedv8 engineIssues and PRs related to the V8 dependency.Issues and PRs related to the V8 dependency.
on Mar 20, 2016 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.
V8 hasn't even optimized most of the ES5 features yet.
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 againstfor (var...)before being used in performance-critical code.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.
FWIW there is a PR (#5819) that fixes this.
@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 makefor (let...)any faster in userland code like in this issue. That will have to wait for v8 to do something awesome.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.
@AlekseyMalyshev Here's the relevant issue in the v8 tracker: https://bugs.chromium.org/p/v8/issues/detail?id=4762
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.