HOME

TheInfoList



OR:

In computer science, ahead-of-time compilation (AOT compilation) is the act of
compiling In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
an (often) higher-level
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
into an (often) lower-level language before execution of a program, usually at build-time, to reduce the amount of work needed to be performed at run time. It is most commonly associated with the act of
compiling In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
a higher-level
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
such as C or C++, or an
intermediate representation An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
such as
Java bytecode Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact ...
or
Common Intermediate Language Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL) or Intermediate Language (IL), is the intermediate language binary instruction set defined within the Common Language Infrastructure (CLI) specification. ...
(CIL) code, into native
machine code In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
so that the resulting binary file can execute natively, just like a standard native compiler. When being used in this context, it is often seen as an opposite of just-in-time (JIT) compiling. Speaking more generally, the target languages of an AOT compilation are not necessarily specific to native
machine code In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
but are defined rather arbitrarily. Some academic papers use this word to mean the act of compiling the
Java bytecode Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact ...
to C or the timing when optimization pipeline are performed. An academic project uses this word to mean the act of pre-compiling JavaScript to a machine-dependent optimized IR for
V8 (JavaScript engine) V8 is a JavaScript and WebAssembly engine developed by Google for its Chrome browser. V8 is free and open-source software that is part of the Chromium project and also used separately in non-browser contexts, notably the Node.js runtime ...
and to a machine independent bytecode for
JavaScriptCore WebKit is a browser engine primarily used in Apple's Safari web browser, as well as all web browsers on iOS and iPadOS. WebKit is also used by the PlayStation consoles starting with the PS3, the Tizen mobile operating systems, the Amazon ...
. Some industrial language implementations (e.g.
Clojure Clojure (, like ''closure'') is a dynamic programming language, dynamic and functional programming, functional dialect (computing), dialect of the programming language Lisp (programming language), Lisp on the Java (software platform), Java platfo ...
and Hermes
JavaScript engine The first engines for JavaScript were mere interpreters of the source code, but all relevant modern engines use just-in-time compilation for improved performance. JavaScript engines are typically developed by web browser vendors, and every maj ...
) use this word to mean the act of pre-compiling the source language to VM specific bytecode.
Angular (web framework) Angular (also referred to as Angular 2+) is a TypeScript-based Free and open-source software, free and open-source Single-page application, single-page Web framework, web application framework. It is developed by Google and by a community of indi ...
uses this word to mean converting its
HTML Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
template and
TypeScript TypeScript (abbreviated as TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications and transpiles to JavaScript. It is developed by Micr ...
to
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
. In fact, since all static compilation is technically performed ahead of time, this particular wording is often used to emphasize examples where there are significant performance advantages over the act of such pre-compiling. The act of compiling
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
to
Java bytecode Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact ...
is hence rarely referred to as AOT since it is usually a requirement, not an optimization.


Reduced runtime overhead

Some programming languages with a
managed code Managed code is computer program code that requires and will execute only under the management of a Common Language Infrastructure (CLI); Virtual Execution System (VES); virtual machine, e.g. .NET, CoreFX, or .NET Framework; Common Language R ...
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 In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usua ...
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 In computer programming, a runtime system or runtime environment is a sub-system that exists in the computer where a program is created, as well as in the computers where the program is intended to be run. The name comes from the compile time ...
, 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.


Performance trade-offs

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 In object-oriented programming such as is often used in C++ and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method that is dispatched dynamically. Virtual functions are an important part ...
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.


Storage trade-offs


See also

* asm.js compiler (
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
) * Bartok ( CIL) * Excelsior JET (
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
) * GNU Compiler for Java * IL2CPU (CIL) *
Native Image Generator The Native Image Generator, or simply NGen, is the ahead-of-time compilation (AOT) service of the .NET Framework. It allows a CLI assembly to be pre-compiled instead of letting the Common Language Runtime (CLR) do a just-in-time compilation ( ...
(CIL) *
RubyMotion RubyMotion is an IDE of the Ruby programming language that supports iOS, OS X and Android. RubyMotion is a commercial product created by Laurent Sansonetti for HipByte
(
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
)


References


External links


Speed: NGen Revs Up Your Performance with Powerful New Features – MSDN Magazine, April 2005

Mono AOT


* ttps://web.archive.org/web/20160802232148/http://gcc.gnu.org/java/ GNU Compiler for Java
AOT compilation of asm.js


* ttp://linux.sys-con.com/read/46901.htm Improving Swing Performance: JIT vs AOT Compilation – LinuxWorld Magazine, November 2004{{Webarchive, url=https://web.archive.org/web/20080612163029/http://linux.sys-con.com/read/46901.htm , date=2008-06-12
Manta
Compilers