Le 13/07/2013 10:21, Brian Di Palma a écrit :
I was just wondering
if the 'const' keyword would help give JS another small performance
boost.
Unlikely. Const can be almost statically inferred (no assignment to a
given variable). The "almost" refers to cases where eval happens. Worst
case, if there is no assignment, a variable can be optimistically
optimized as const. If the value is changed via eval, then de-optimize
(but in practice, eval is rare, so the optimistic optimization will be
worth it)
As Andreas points out the major issue is that JS is highly dynamic,
this can be very useful sometimes but for most code it's not required.
Maybe if you mark everything as const or freeze/seal classes then
maybe JS engines will optimize for that code.
JS engines already optimistically optimize assuming code remains stable
(for objects, V8 has "hidden classes", SpiderMonkey has the equivalent
"shape" feature) and deoptimizes when the dynamic features are being used.
It might be one of the reason why maps are better at being maps than
objects (since objects seem to have been optimized for cases where they
are stable)
David
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss