By Kshitiz Gupta



4 July 2012

Traditionally, computer programs can be executed in three possible ways – interpreted, static (ahead-of-time) compilation and Just In time (JIT). In interpreted mode, the code is translated from high-level language to low level language during execution whereas in ahead-of-time compilation the high-level language code is converted to low-level machine code before hand. JIT (Just in time) compilation is a hybrid approach of the two. Here the code translation into native code occurs during the execution time and the translated code is cached so that this conversion need not be done every time. Obviously there is a small penalty when compared to ahead-of-time compilation as there is a cost associated with this translation.
After this brief introduction lets get into the Adobe AIR world and what is there in it for an iOS AIR developer. SWF content on all platforms other than iOS is JIT compiled, whenever possible. The swf is downloaded locally and JIT compiled where possible.
Let us now look at what is different on iOS. JIT compilation requires that a memory block be writable as well as be marked executable. Writable so that JIT compiled code can be written there and executable for obvious reasons that it can be run. iOS disallows a memory block to be marked both executable and writable simultaneously. This makes it impossible to JIT compile on iOS. I would like to mention here that mobile Safari is allowed to bypass this restriction and JIT is allowed probably to allow faster execution of Javascript. To put it simply the code needs to be compiled ahead-of-time into native code to make it run faster on iOS.
When your actionscript code is AOTed then the actionscript bytecode is compiled into native code. Your application on iOS also includes a copy of runtime. It is important to understand that the code within the runtime is already native compiled. So ahead-of-time compilation of your application will not have any impact on the performance of the runtime code. What do I mean by runtime code then? Runtime code includes things that execute within the runtime like bitmapdata.draw or the antialiasing of your vectors. Ahead-of-time compilation does not impact this code. AOT is only applicable to Actionscript code and not to Runtime code. Applications that have a lot of actionscript code or are built using frameworks (like Flex), which inherently are actionscript intensive benefit greatly because of ahead-of-time compilation. By actionscript intensive I mean code that performs lot of computations within Actionscript (for example, XML parsing).
Actionscript compilation
Only actionscript part of your application is converted to native code when doing ahead of time compilation. Runtime code is already native compiled.
It is important to realize that ahead-of-timecompilation is not a magic bullet for performance. If your application is not actionscript intensive then ahead-of-time compilation and interpreter mode may have the similar performance. You can use this fact during your app development cycle.  Considering that ahead-of-time compilation takes more time than interpreter apps you may use interpreter mode for your development cycle. Sometimes developers are just intensely working on improving the performance of their application. And to verify this they may be using aot mode for compilation. They can save time and use interpreter mode even for this part of development cycle if their application is not actionscript intensive. Obviously for publishing the application you should use the ahead of time compiled ipa since you will compile just once at the end.