What is AOT Compilation?
AOT compilation means that your JavaScript code is compiled entirely to WebAssembly (or native code) before execution, not during runtime. This is in contrast to:- Interpreters: Execute code line-by-line at runtime (slow but simple)
- JIT compilers: Compile hot code paths during execution (fast after warmup)
- AOT compilers: Compile everything before execution (fast from the start)
Key Characteristics
Zero Runtime/Preluded Code
Porffor generates WebAssembly with zero constant runtime or preluded code. Every piece of code in the output is generated specifically for your program:Only the code you write and the builtins you use are included
No heavy runtime library shipped with every program
Minimal WebAssembly imports (only I/O operations)
Compilation Pipeline
The AOT compilation process follows these steps:The parser (Acorn) is the only external dependency. Everything else—from bytecode generation to final assembly—is built from scratch.
Compilation Targets
Porffor’s AOT approach enables multiple compilation targets:WebAssembly
Compile to
.wasm files for web or Wasm runtimesNative Binaries
Compile to native executables via 2c (Wasm → C → binary)
C Source
Generate C code for maximum portability
Direct Execution
Run immediately via Porffor’s runtime
Advantages
Predictable Performance
Unlike JIT engines, performance doesn’t vary based on warmup:Small Output Size
Without a runtime, compiled programs are remarkably small:Security
AOT compilation provides inherent security benefits:No dynamic code generation at runtime
All code known and analyzed before execution
Wasm’s sandboxed environment
Memory-safe compilation (JavaScript → Wasm)
Limitations
No Dynamic Code Execution
Because everything is compiled ahead of time, dynamic code evaluation is impossible:Limited Runtime Flexibility
JIT engines can optimize based on runtime patterns. Porffor must make all decisions at compile time:- Type specialization happens at compile time (not runtime)
- No dynamic recompilation based on usage patterns
- Cannot adapt to changing execution patterns
Optimization Levels
Porffor provides multiple optimization levels:- -O0
- -O1 (default)
- -O2
Type-Guided Optimization
Use TypeScript annotations to help the compiler optimize:Porffor doesn’t type-check your code, but uses type annotations as compiler hints for better optimization.
Comparison with Other Engines
| Feature | Porffor (AOT) | V8/SpiderMonkey (JIT) | QuickJS (Interpreter) |
|---|---|---|---|
| Startup time | Instant | Slower (warmup) | Instant |
| Peak performance | Good | Excellent | Poor |
| Binary size | Tiny | Large | Medium |
| Memory usage | Low | High | Medium |
| Dynamic eval | ❌ | ✅ | ✅ |
| Predictability | High | Low | High |
Performance Characteristics
From the README:For the features it supports, Porffor is blazingly fast compared to interpreters and engines without JIT. With JIT engines, Porffor can match or exceed performance with compiler arguments, typed input, and native compilation.
Next Steps
Type System
Learn about Porffor’s type system and ByteStrings
Memory Model
Understand memory management and pointers
Compiler Options
Explore all compilation flags
Native Compilation
Compile JavaScript to native executables