Hacker News new | ask | show | jobs
An update on strong mode (groups.google.com)
75 points by joajoa 3775 days ago
3 comments

> ES6 performance sucks! Strong mode is a mode for ES6, you cannot use it without using various ES6 features. However, idiomatic ES6 code currently is substantially slower than ES5, across all browsers -- easily by 2x, often by 10x or more. Due to the sheer size of ES6, plus a number of unfortunate design choices, it will likely take years until implementations catch up with ES5 optimisations, and the hundreds of man years that went into those.

This has been my suspicion for a while. Perhaps I've missed other comments to this effect, but I don't think I've heard anyone else articulate it.

There's definitely a lot of room for improvement. The V8 team has been working on finishing baseline implementations for all of ES6 before spending significant time optimizing particular features. But improvements are coming quickly! In the last few weeks, for example, ES6 rest parameters got 8-10x faster and Object.assign() is now as fast as _.assign() [0].

In general, we will focus on improving the performance of the most-used features first. Arrow functions, generators, etc. are high on the list.

[0]: https://twitter.com/addyosmani/status/699976753255751681

(Disclaimer: I'm a PM on the V8 team)

I appreciate the information. I'm curious, in reference to the original quote, how much of the existing ES5 optimization story do you think can be leveraged (at least within V8) to bring ES6/7 on par with raw ES5 and how much needs to be greenfield optimizations?
A big difference between ES5 and ES6/7 is that the former passes through our old, highly-tuned optimizing engine Crankshaft [0] and the latter passes through our new optimizing engine TurboFan [1]. The team's expertise optimizing Crankshaft can certainly be leveraged in TurboFan, but it's not an apples-to-apples comparison. In the future, TurboFan will handle ES5 code as well.

tl;dr we're changing engines mid-flight and that has as much to do with performance differences as the ES6 features themselves.

[0]: http://blog.chromium.org/2010/12/new-crankshaft-for-v8.html [1]: http://v8project.blogspot.com/2015/07/digging-into-turbofan-...

I wonder which features are slow. I'm assuming generators and by extension the for-of syntax, which is otherwise a thing of beauty. I imagine proxies are somewhere between slow and horrifyingly slow.

I have noticed that none of the features I'd hoped would save cycles (const, generators, fat arrow functions) seem to be helping at all in the browsers of today.

When last I checked, V8 simply triggers a deopt when it encounters any ES6 syntax at all - so just putting an unused "let foo;" in a function will kill its performance, regardless of whether any ES6 features are used.

Of course, it may be that some ES6 features will still be slow even after they've been optimized for, but right now, as a practical matter, I think ES6 is slow simply because the engines don't yet optimize it.

Last time I checked, fat arrow functions have a performance penalty because of all the optimisations that's made around scope in regular ES5 functions can't be used.

I believe ES6 fat arrow functions are slow for a similar reasons as why regular functions are slow when you use the magic arguments variable.

Regarding the scope optimizations: that's an interesting point. I wonder if the different scoping of let/const also create a performance penalty versus var.
This is true as well.
I wouldn't be surprised if const and arrow functions actually make things slower. const, or at least a naive implementation of it, requires checking if the value is changed which var does not. Perhaps that could be equally performant in time.

Arrow functions seem like they would take (marginally) longer to parse than explicit function declarations due to having a more verbose AST that does not start with unambiguous tokens. That, and you have the implicit this binding which must come with a cost. Again, in time this might be okay.

Wouldn't const be checked at compile time?
That's still a check that var is not subject to. Hence, it's a little slower (in theory).
In theory, the opposite, because a compiler knows that a constant binding never changes so the value it references can be inlined everywhere it is used without having to do runtime checks. But I think engines are not doing this yet.
How does native ES6 performance compare with the performance of ES6 compiled into ES5?

Because right now there isn't enough cross-browser ES6 support to be able to use it reliably with compilation; given that the compilation procedure is easy and relatively pain-free (at least until you see the horrifying code that Babel produces when you ask it to transpile generators), I'm wondering how much of an issue ES6 performance is in the real world.

For those who were wondering what strong mode is, this is a post to the Strengthening JS group, which for discussion of "strong mode and type system extensions that the V8 team is working on."

Strong mode is "a new language mode (an extension of strict mode) that implements a stronger semantics by removing brittle or costly features."

https://developers.google.com/v8/experiments

The conclusion is that "we have reluctantly decided not to pursue strong mode further."

Additional quotes:

Not all is lost. We continue to investigate the addition of types to V8. And in fact, typing may bring some of the benefits of strong mode for lower cost.

...probably have us readjust our design goals. In particular, we no longer believe that requiring type soundness _by default_ can ever work successfully in JavaScript.

Why does one of the comments on that thread say strong mode is dead? Everyone seemed to ignore the comment.
Because it _is_ dead. Relevant excerpt from the OP:

TAKE-AWAY

Considering all that, we have reluctantly decided not to pursue strong mode further. We learned some worthwhile lessons, but overall it is not clear that the benefits justify the costs. Starting with the next version of V8, we will hence remove support for strong mode.

"An update on X" is a google meme for "X is dead"