V8 has optimized new JavaScript language features (2018)
1–10 of 53 posts
Re: V8 has optimized new JavaScript language features (2018)
#2Re: V8 has optimized new JavaScript language features (2018)
#3Re: V8 has optimized new JavaScript language features (2018)
#4This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
Re: V8 has optimized new JavaScript language features (2018)
#5> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
Re: V8 has optimized new JavaScript language features (2018)
#6> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
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 your code, and optimise around them, while having (ideally cheap) checks in place to ensure the assumptions continue to hold.
Re: V8 has optimized new JavaScript language features (2018)
#7> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
https://github.com/thlorenz/v8-perf/blob/master/language-fea...
Re: V8 has optimized new JavaScript language features (2018)
#8> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
Re: V8 has optimized new JavaScript language features (2018)
#9> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
Wouldn't "looking at the let" take some cpu time?
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 low as to be virtually unmeasurable anyway. (It is such a trivial check, much simpler than almost everything else the compiler does.)
(However, see rewq4321's sibling comment about analysability and JavaScript being a very dynamic language when "eval" is used.)
Re: V8 has optimized new JavaScript language features (2018)
#10> const performs a lot better in optimized code than var or let This puzzles me; if only ever one value is assigned, I would have expected at least let to perform identically to const in optimised code, because I expect the optimiser to look at the let and say “never reassigned, turn it into a const ”. By the sound of it, I’m wrong, and I’d be interested to know why I’m wrong.
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…