T08 Dec 18, 2025 2 min read

Compilation

The process of translating source code into a lower-level representation (often machine code), checking and optimizing along the way.

Definition

Compilation is the process of translating source code into a lower-level representation that a machine can execute or further process.

In many cases the output is machine code: machine instructions that a CPU can run.

Compilation can also produce intermediate outputs (bytecode, IR) that will be executed by a runtime or later combined via linking.

  • Related: compiler, assembler, intermediate representation (IR), bytecode
  • Adjacent steps: linking, packaging into an artifact

Typical stages (conceptual)

  • Parsing and validation (does the program make sense in the language?).
  • Transformations and optimizations (rewrite to run faster, use less memory, etc.).
  • Emitting artifacts (often object code and metadata that later become part of a final binary).

Different compilers split these stages differently, but the core idea is always translation plus checks.

A useful analogy

Think of compilation as translating a high-level set of instructions (human language) into a precise, constrained format that the execution engine understands. A good translation preserves meaning, rejects invalid sentences, and may rearrange phrasing to be more efficient without changing the result.

AOT vs JIT compilation

  • AOT compilation runs before the program starts and produces an artifact you ship.
  • JIT compilation runs during execution, compiling what’s hot or what’s needed right now.

What compilation influences in production

Compilation isn’t only a developer-time concern. It affects:

  • Portability: what CPU/OS the resulting artifact can run on.
  • Performance characteristics: instruction selection, inlining, vectorization, and other decisions that shape runtime speed.
  • Startup time: how much work is done before the program starts (AOT) vs during startup (JIT/warmup).
  • Debuggability: whether debug symbols exist, whether stack traces are readable, whether optimizations obscure stepping.
  • Security properties: hardening flags, control-flow integrity options, and other compiler-level mitigations (platform-dependent).

Common misconceptions

  • “Compiled” vs “interpreted” is not binary. Many systems compile to bytecode, then interpret and/or JIT compile to machine code.
  • “Optimized build” isn’t universally better. Heavy optimizations can trade debuggability for speed.
  • “Same source code” does not guarantee identical machine code: compiler versions, flags, target CPU, and link settings can change outputs.

Compilation vs linking

Compilation translates source code into compiled units. Linking combines those units (and libraries) into a final artifact such as an executable.