AOT or Interpreter

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).

Only actionscript part of your application is converted to native code when doing ahead of time compilation. Runtime code is already native compiled.

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.


6 Responses to AOT or Interpreter

  1. radyo dinle says:

    i use AOT thanks fort his information.

  2. where I can read which exactly features refers to “Runtime code” ?

    • Kshitiz Gupta says:

      By runtime code I mean all code that executes in response to any API that you have called in Actioscript. All API calls execute some code within the runtime (Flash player or AIR). A simple example could be using a loader to load a jpg image and then to display it. The runtime internally will make calls to fetch the image, decompress the image, update the display list and then proceed to draw the image on the display device.

  3. Andrew Frost says:

    “Applications that have a lot of actionscript code … benefit greatly because of ahead-of-time compilation.”
    How can we set up a project to create AOT-compiled ActionScript? Is this something that’s just iOS-specific (i.e. it happens when you publish for the iOS platforms) or could I do this for another platform as well using Flash Professional or Flash Builder?

  4. Why are only iOS – Apps AOT compiled. I think compiling Android-Apps in AOT too would increase the performance dramatically.

  5. Pingback: (转)Adobe AIR读取本地外部SWF文件的功能概览 | 湖心小筑