Some programming languages with a managed code runtime that can be compiled to an intermediate representation use just-in-time (JIT) compiling. This briefly compiles intermediate code into machine code for a native run while the intermediate code is executing which may slow an application's performance. Ahead-of-time compiling eliminates the need for this step by occurring before execution rather than during execution.
Ahead-of-time compiling for dynamically typed languages to native machine code or other static VM bytecode is possible in a limited number of cases only. For example, the High Performance Erlang Project (HiPE) AOT compiler for the language Erlang can do this because of advanced static type reconstruction techniques and type speculations.
In most situations with fully AOT compiled programs and libraries, it is possible to remove part of a runtime environment, thus saving disk space, memory, battery life, and startup times (no JIT warmup phase), etc. Because of this, it can be useful in embedded or mobile devices.
AOT compilers can perform complex and advanced code optimizations which in most cases of JITing will be considered much too costly. In contrast, AOT usually cannot perform some optimizations possible in JIT like runtime profile-guided optimization (PGO), pseudo-constant propagation, or indirect-virtual function inlining. AOT must compile to a target architecture while a JIT can compile the code to make the best use of the actual CPU it is running on, even years after the software has been released.
Further, JIT compilers can speculatively optimize hot code by making assumptions on the code. The generated code can be deoptimized if a speculative assumption later proves wrong. Such operation slows the performance of the running software until code is optimized again by adaptive optimization. An AOT compiler cannot make such assumptions and needs to infer as much information as possible at compile time. It needs to resort to less specialized code because it cannot know what types will go through a method. Such problems can be alleviated by profile-guided optimizations. But even in this case, the generated code cannot be adapted dynamically to the changing runtime profile as a JIT compiler would do.
Jung, Dong-Heon; Park, Jong Kuk; Bae, Sung-Hwan; Lee, Jaemok; Moon, Soo-Mook (2006-10-22). "Efficient exception handling in Java bytecode-to-c ahead-of-time compiler for smbedded systems". Proceedings of the 6th ACM & IEEE International conference on Embedded software - EMSOFT '06. Seoul, Korea: Association for Computing Machinery. pp. 188–194. doi:10.1145/1176887.1176915. ISBN 978-1-59593-542-7. S2CID 15591457. 978-1-59593-542-7 ↩
Chambers, Craig (2002-01-14). "Staged compilation". Proceedings of the 2002 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulation. PEPM '02. Portland, Oregon: Association for Computing Machinery. pp. 1–8. doi:10.1145/503032.503045. ISBN 978-1-58113-455-1. S2CID 18546907. 978-1-58113-455-1 ↩
Zhuykov, R.; Sharygin, E. (2017-01-01). "Ahead-of-time compilation of JavaScript programs". Programming and Computer Software. 43 (1): 51–59. doi:10.1134/S036176881701008X. ISSN 1608-3261. S2CID 2338849. https://doi.org/10.1134/S036176881701008X ↩
ispras/v8-aotc, Ivannikov Institute for System Programming of the Russian Academy of Sciences, 2021-01-30, retrieved 2021-03-17 https://github.com/ispras/v8-aotc ↩
ispras/webkit-aotc, Ivannikov Institute for System Programming of the Russian Academy of Sciences, 2021-01-30, retrieved 2021-03-17 https://github.com/ispras/webkit-aotc ↩
"Clojure - Ahead-of-time Compilation and Class Generation". clojure.org. Retrieved 2021-03-17. https://clojure.org/reference/compilation ↩
"Hermes: A new open source JavaScript engine optimized for mobile apps". Facebook Engineering. 2019-07-12. Retrieved 2021-03-17. https://engineering.fb.com/2019/07/12/android/hermes/ ↩
"Angular". angular.io. Retrieved 2021-03-17. https://angular.io/guide/aot-compiler ↩