# Ahead of time (AOT) compilation
Ahead-of-Time (AOT) compilation is a technique in computer science where source code (or an intermediate representation of it) is compiled into a lower-level language, typically native machine code, before the program is executed. This process usually happens during the build phase of a software project.
**Key Characteristics of AOT Compilation:**
- Pre-execution Compilation: The most defining characteristic is that the compilation happens before the program starts running. This is in contrast to Just-in-Time (JIT) compilation, where compilation occurs during runtime.
- Target: Lower-Level Language: AOT compilers typically convert higher-level languages (like C++, Java bytecode, or TypeScript in Angular) into machine-specific assembly or binary code that the computer's processor can directly understand and execute.
- Build-Time Process: AOT compilation is often integrated into the software build process. When you "build" your application, the AOT compiler does its work, producing a ready-to-run executable.
**Why is AOT Compilation Used?**
The primary goal of AOT compilation is to reduce the amount of work that needs to be performed at runtime. This leads to several significant benefits:
- Faster Startup Time: Since the code is already compiled, the application doesn't need to spend time compiling at startup. This results in quicker launch times.
- Improved Performance: AOT compilers can perform more extensive and complex optimizations because they have more time and resources available during the build phase than a JIT compiler typically has at runtime. This can lead to faster execution of the program.
- Reduced Runtime Overhead: No runtime compilation means less CPU and memory usage during program execution, as there's no need to load and run a compiler alongside the application.
- Smaller Bundle Size (in some contexts): In frameworks like Angular, AOT can eliminate the need to ship the compiler itself to the client, resulting in smaller application bundles.
- Earlier Error Detection: Template or binding errors in frameworks like Angular can be caught during the build process with AOT, rather than only at runtime when users might encounter them.
-Enhanced Security: By pre-compiling templates and components into JavaScript, AOT can reduce opportunities for injection attacks as there's less dynamic code evaluation in the browser.