Earlier quoted context omitted.
The const keyword also guarantees that once a value is assigned to its slot it won't change in the future. As a result TurboFan skips loading and checking const slot values slots each time they are accessed (Function Context Specialization) https://github.com/thlorenz/v8-perf/blob/master/language-fea...
Right... but the question was 'why can't the same thing be done with let'. The answer is probably a combination of 'they haven't gotten around to it yet', 'they don't see the need', 'they don't want the complexity', and 'they don't want to spend compile time doing that.'
V8 has optimized new JavaScript language features (2018)
21–30 of 53 posts
Re: V8 has optimized new JavaScript language features (2018)
#22In stark contrast: "Using const/let instead of var can make JavaScript code run 10× slower in Webkit" ;P. https://news.ycombinator.com/item?id=24844353
I know you jest, but I don't think that's a good example of "contrast" between the engines. That was just a bug/oversight and fixed in a couple of weeks after it was reported [1]. [1]: https://trac.webkit.org/changeset/269115/webkit
It was an excellent bug report, complete with a reproducible example.
Only after it recently made the rounds on Twitter and hn was it fixed.
https://mobile.twitter.com/mraleph/status/132175888792258969...
Re: V8 has optimized new JavaScript language features (2018)
#23Earlier quoted context omitted.
Right... but the question was 'why can't the same thing be done with let'. The answer is probably a combination of 'they haven't gotten around to it yet', 'they don't see the need', 'they don't want the complexity', and 'they don't want to spend compile time doing that.'
Because you cannot know whether the let variable is changing just with static analysis without running the associated code, right?
Otherwise it has the same issues as const (is there a temporal dead zone violation?)
Re: V8 has optimized new JavaScript language features (2018)
#24Earlier quoted context omitted.
Right... but the question was 'why can't the same thing be done with let'. The answer is probably a combination of 'they haven't gotten around to it yet', 'they don't see the need', 'they don't want the complexity', and 'they don't want to spend compile time doing that.'
Because you cannot know whether the let variable is changing just with static analysis without running the associated code, right?
You're not doing static analysis - you're doing dynamic analysis and speculation. But this has the downsides I said - it's more complicated, it takes more time, etc.
Re: V8 has optimized new JavaScript language features (2018)
#25Earlier quoted context omitted.
JavaScript is very dynamic. Here I define a variable with `let` and then change it: let foo = 10; eval("fo"+"o = 10"); I could "obfuscate" that eval assignment as much as I like. So you can't completely statically analyse `let` variables. That said, it's likely you'd end up with perf very close to `const` in a very "hot" part of your code, since a good JIT compiler like V8 will eventually make "assumptions" about you…
An interesting point, however direct "eval" is a special case. It's already known that functions containing direct "eval" are not subject to the same level of performance optimisations as other functions. There is no way to obscure the call to direct "eval" itself; the compiler knows clearly whether it occurs. Without "eval" appearing syntactically inside a function's scope, there is no dynamic access to "let" variab…
Jsfuck would like to have a word with you
Re: V8 has optimized new JavaScript language features (2018)
#26Earlier quoted context omitted.
Wouldn't "looking at the let" take some cpu time?
"Looking at the let" refers to code analysis during JIT compile time, which happens once for each bit of code, not run time which happens many times as the same bits of code are run. When comparing the speed of "const" versus "let", the JIT compile time is irrelevant; the speed differences being looked at are entirely run time, inside loops. Also the JIT compile time difference from "looking at the let" will be so lo…
Re: V8 has optimized new JavaScript language features (2018)
#27Earlier quoted context omitted.
An interesting point, however direct "eval" is a special case. It's already known that functions containing direct "eval" are not subject to the same level of performance optimisations as other functions. There is no way to obscure the call to direct "eval" itself; the compiler knows clearly whether it occurs. Without "eval" appearing syntactically inside a function's scope, there is no dynamic access to "let" variab…
> There is no way to obscure the call to direct "eval" itself; Jsfuck would like to have a word with you
Re: V8 has optimized new JavaScript language features (2018)
#28Earlier quoted context omitted.
An interesting point, however direct "eval" is a special case. It's already known that functions containing direct "eval" are not subject to the same level of performance optimisations as other functions. There is no way to obscure the call to direct "eval" itself; the compiler knows clearly whether it occurs. Without "eval" appearing syntactically inside a function's scope, there is no dynamic access to "let" variab…
> There is no way to obscure the call to direct "eval" itself; Jsfuck would like to have a word with you
Re: V8 has optimized new JavaScript language features (2018)
#29Does anyone have information on using the term "exotic"? I haven't heard that before and not sure how to understand what they meant by that.
Re: V8 has optimized new JavaScript language features (2018)
#30"entirely new approach to how bound function exotic objects are implemented" Does anyone have information on using the term "exotic"? I haven't heard that before and not sure how to understand what they meant by that.