3 ms·
function main() { let myNum = 0; for (let i = 0; i <= ITERATIONS; i++) { myNum *= i; myNum++; } } I'm a lit
by fenomas 5y ago
function main() {
let myNum = 0;
for (let i = 0; i <= ITERATIONS; i++) {
myNum *= i;
myNum++;
}
}
I'm a little surprised that turbofan doesn't JIT that into an empty function, given that it has no return value or side effects.
- titzer 5y agoIt doesn't eliminate loops, but it almost certainly is an empty loop after the full pipeline of optimizations and scheduling. I'm guessing the C version is unrolled or even completely eliminated, because LLVM will definitely eliminate empty loops.
- fenomas 5y agoIt feels like it ought to, but I did some light testing in the browser and it seems that V8 never optimizes it into an empty loop, even after it's hot code for a long time. I know turbofan does LICM, but I don't think it knows how to catch cases like this.