8.7 Loop unrolling

since Haxe 4.0.0

The compiler tries to unroll short iterations of for loops over constant ranges. This can produce faster code without the use of a loop:

for (i in 0...4) {
  test(i);
}

The above code turns into something similar to:

test(0);
test(1);
test(2);
test(3);

Whether a loop is unrolled or not depends on the loop unrolling cost, which is defined as the number of iterations of the loop and the number of expressions inside the loop body. This threshold is 250 by default but can be configured using the -D loop_unroll_max_cost=... compile-time define.