HaXe to AS3 converted.

HaXe now comes with the ability to output AS3 code directly. Hopefully this ability will close the performance gap between haXe and AS3.

I first used this option straight out fo the box to convert the three benchmarks used on this site. I had to modify the generated code to include the “override” and “virtual” keywords – but I imagine this will be fixed in later versions of haXe.
Then I came accross a curious result – the AS3 code was no faster than the haXe for the CarDemo code. However, since the code was right there in front of me, I could compare the differences with the AS3 code before it was converted to hx. A quick inspection showed the the culprit was a type-cast used in the inner loop of the collision detection code. So I rewote the code to avoid type-casting if possible, and got a 2 times speedup on the haXe code! See [CarDemo hx v2](/?page_id=30) for this compiled haXe programme. I then ran the hx->as3 converter again and got something that ran faster than the original as3 code!

AS3 haXe haXe typed haXe via AS3 haXe – less casting
CarDemo 7.6 ms 38.6 ms 38.9 ms 6.5 ms 15.0 ms
SimpleLoop – for 115 ms 1218 ms 74 ms 40 ms
SimpleLoop – while 115 ms 1020 ms 76 ms 50 ms
PerfTest 1 – string manipulation, join 238 ms 383 ms 720 ms 229 ms
PerfTest 2 – string sort 620 ms 1284 ms 195 ms 1989 ms
PerfTest 3 – string addition 125 ms 138 ms 130 ms 130 ms
PerfTest 4 – bit string manipulation 125 ms 134 ms 125 ms 117 ms
PerfTest 5 – floating point ops 2 ms 24 ms 2 ms 2 ms
PerfTest 6 – substr 2 ms 7 ms 7 ms 3 ms
PerfTest 7 – string indexOf 58 ms 75 ms 75 ms 56 ms
PerfTest 8 – Math.round/random 6 ms 38 ms 24 ms 6 ms
PerfTest 9 – integer addition 31 ms 343 ms 27 ms 29 ms
PerfTest 10 – string function calls 34 ms 103 ms 104 ms 45 ms
PerfTest 11 – MD5 68 ms 163 ms 171 ms 49 ms
PerfTest 12 – integer function calls 1 ms 14 ms 9 ms 2 ms

For all but the string-sort code, the results were as good as the AS3 code. This is an extremely satisfting result because it means that we can write our web programmes in haXe, without fear of performace loss.

This concludes the investigation into the viability of using haXe for web based games, and next I will turn my attention to using the same haXe code base for stand alone game development.