3 ms·
IonMonkey does loop invariant code motion as well, and of course it's not "naughty", that's a widely used and standard compilation technique. It's also exactly
by magicalist 14y ago
IonMonkey does loop invariant code motion as well, and of course it's not "naughty", that's a widely used and standard compilation technique. It's also exactly what you want: there are many instances when keeping an invariant statement inside a loop results in clearer code, and there's no reason you should have to realize that and make your code more awkward and less maintainable when it's something the compiler can handle easily.
What it sounds like you're describing is that people are still writing terrible benchmarks. The days of this sort of thing on jsperf being useful are numbered:
function benchmark() {
for (var i = 0; i < 1000000; i++) {
var result = computationWithNoSideEffects();
}
}
Yes, a good compiler will turn that into a noop. And no, that's not being naughty either. It's just a terrible benchmark.
(also, when using crankshaft, doubles in V8 are unboxed and not allocated on the heap).