Repository navigation
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
|=------------------------------------------------------------------=|
.---===~ Luamura ~===---.
This is a fork of Lua 5.5.1, released on 24 Jul 2026.
For installation instructions, license details, and
further information about Lua, see doc/readme.html.
|=------------------------------------------------------------------=|
--[ Table of Contents
0 - Motivation
0 - Overview
1 - Benchmarks
--[ Motivation
Luamura is an AOT Baseline compiler for lua. The primary goal is to
eliminate the interpreters dispatch overhead. Luamura achieves this by
applying the first Futamura projection, deriving a compiled binary by
specializing the interpreter to a fixed bytecode.
When seeking performance over an interpreter, why not use a JIT? There are
several deployment settings where JIT compilation may not be appropriate or
even possible. Sandboxed WASM execution, for instance, can not use dynamic
executable memory. Interpreters/VMs are therefore the only option since they
have static executable memory. JITs may also be more memory intensive,
require an expensive warmup phase, and have a propensity for bugs.
--[ Overview
The set of AOT compiled function are emited into a binary which links
liblua. These functions are marked with an AOT flag in the Prototype. Native
functions can, and often do, bail out or dispatch to VM routines for garbage
collection, debug handling, co-routine scheduling, etc. This is what allows
Luamura to be a compliant implementation with relatively little effort. It
is also limits the Baseline performance. All dispatches into the VM are
opaque, and make analysis imprecise. Moreover, any VM call can mutate the
stack, PC, etc, which forces native-compiled code to be defensive around
each call.
To natively compile Lua, each function is a module is lexed, parsed and
lowered into bytecode. A control-flow-graph (CFG) is constructed from the
instructions in each function. The Baseline compiler receives the CFG and
iterates over its blocks. For each bytecode instruction within a block, the
IR builder emits a call to the respective op-handler function, marked with
the always-inline attribute. A straight-line sequence of Lua bytecode then
compiles down into each op-handler stitched together, with no dispatch
overhead.
In order to make each op-handler visible, the interpreter is modified to
also expose each op-handler as a function. The interpreter retains its
computed-goto (threaded) dispatch. Luamura achieves a geometric mean speedup
of 1.19x on Are We Fast Yet? (AWFY) in the run below.
1 - AWFY Benchmarks
Benchmark Lua (s) luamura (s) Speedup
---------------- -------- ----------- --------
Bounce 0.8968 0.6929 1.29x
CD 2.0486 1.8946 1.08x
DeltaBlue 0.6643 0.5932 1.12x
Havlak 5.3710 5.2363 1.03x
Json 0.8337 0.7955 1.05x
List 0.6362 0.4968 1.28x
Mandelbrot 0.5281 0.3631 1.45x
NBody 0.6402 0.4605 1.39x
Permute 0.7977 0.7204 1.11x
Queens 0.4673 0.4086 1.14x
Richards 3.0171 2.7211 1.11x
Sieve 0.6137 0.3718 1.65x
Storage 1.4100 1.2773 1.10x
Towers 0.9097 0.8556 1.06x
---------------- -------- ----------- --------
Geometric mean 1.19x