This is something to consider for intensive loops in AS3 and is probably not a bad idea to use in general although the gains may be minimal. I was reading about the benefits of strict type annotations in Actionscript 3 and how they are handled in the new VM. There have been other studies that show 20% increase in speed for loops that take advantage of Array() fast pathing. So, let’s see how it works…
The slower way:
Notice that within the loop ‘n’ is multiplied by 4 and therefore promoted to a Number.
[as]
var n:int;
for(n=0;n<1000;n++){
_array[n*4] = 2;
}
[/as]
The faster way:
Notice how the result of the operation is cast back to the int type to take advantage of fast path indexing in the array.
[as]
var n:int;
for(n=0;n<1000;n++){
_array[int(n*4)] = 2;
}
[/as]
More information about this topic can be found here: http://www.onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf
