News for hackers. Stuff that matters.
Re:V8 has optimized new JavaScript language features (2018) by chrisseaton on Saturday November 07, 2020 @03:17PM (#25018791)
These checks can be completely free, in terms of runtime cost, through deoptimisation.
Re:V8 has optimized new JavaScript language features (2018) by gfxgirl on Saturday November 07, 2020 @08:29PM (#25021897)
How? You have to do some kind of check with let, and you don't with const.
Re:V8 has optimized new JavaScript language features (2018) by miloignis on Sunday November 08, 2020 @02:31AM (#25023875)
Not sure if V8 does this, but a general strategy used in HotSpot is to compile assuming the good case and install a "trap" to deoptimize the code if the condition is violated. So you could compile the let like a const with no checks on the use of the variable, but have a trap such that if any code ever tries to assign to that variable, all code compiled under the assumption that it was constant is throw out.