Loft runs a program four ways: the interpreter, native (compiled through C99 via --native or --ship), WebAssembly (--native-wasm, compiled from C via clang for WASI), and — for comparison — a hand-written Rust version of the same benchmark. The table below shows the time per operation of the ten engine benchmarks in bench/, loft native (--ship) against its Rust twin.
--ship, cc -O3)
Rust reference (rustc -O)
| Benchmark | loft native | Rust | native ÷ Rust |
|---|---|---|---|
01 fibonacci (recursive fib(30) / fib(31)) |
0.52× | ||
| 02 sum loop (5 M steps of a loop-carried integer mix) | 0.70× | ||
| 03 prime sieve (trial division below 300 000) | 1.68× | ||
| 04 Collatz lengths (starts below 200 000) | 1.36× | ||
| 05 Mandelbrot (200×200, 256 iter) | 1.00× | ||
| 06 Newton sqrt (100 000 calls of 50 steps) | 1.36× | ||
| 07 string build (200 000 formatted appends) | 1.16× | ||
| 08 word frequency (hash map, 300 000 operations) | 1.15× | ||
| 09 dot product (2 M floats) | 1.19× | ||
| 10 insertion sort (3 000 integers) | 1.33× |
Time per operation: the median of seven interleaved samples, pinned to one core of an x86-64 Linux machine (bench/portal/results/laptop.tsv), and both lanes printed the same result hash. The source is the performance portal (make perf-portal), which also covers the standard library and the published libraries. Run bench/run_bench.sh from the project root for a quick look on your own hardware, with the Python, loft interpreter and loft wasm lanes beside these two.
Key takeaways
The four loft execution modes have very different performance profiles depending on what the program does.
loft interpreter vs Python
The interpreter runs your program without a separate compilation step. Loft is statically typed, so the interpreter never checks the type of a value at run time; its cost is dispatching each bytecode operation and reaching collection data through the store layer (with looping standard-library helpers compiled ahead of time when a C compiler is available). It is slower than CPython on tight loops and keyed kernels. For hot code, compile with --native or --ship.
loft native vs Rust
The native pipeline compiles loft source to C99 via --native (checked) or --ship (release, cc -O3 with proven-safe fault checks elided), then invokes the host C compiler. Every one of the ten engine benchmarks runs within 1.7× of hand-written Rust: recursion and scalar mixes beat the rustc -O twin (Fibonacci 0.52×, sum loop 0.70×), floating-point kernels match or stay close (Mandelbrot 1.00×, dot product 1.19×, Newton sqrt 1.36×), and text, hash, and sorting workloads sit right alongside them (word count 1.15×, string build 1.16×, insertion sort 1.33×, Collatz 1.36×, prime sieve 1.68×).
loft wasm vs loft native
The wasm build (--native-wasm) compiles the generated C99 via clang for WASI (and --html bundles it for the browser), so it runs anywhere wasmtime or a browser is installed. Arithmetic runs close to native speed; text and store growth trail native slightly because heap expansion inside WebAssembly linear memory goes through memory.grow. Wasm is a good target when native execution is unavailable or portable single-file delivery is the goal.
Bottlenecks
src/c/. Store-backed records keep headers, bounds checks, and null-sentinel handling that hand-written Rust slices and maps avoid.
used library compiles as its own C unit, so a tight caller loop invoking a small scalar helper across a library boundary keeps state in memory where a single-unit Rust build holds it in registers.
src/c/wasm/) live inside WebAssembly linear memory, which grows via memory.grow; workloads that repeatedly grow buffers pay more per reallocation than on native hardware.
Open performance work
- Local collections outside the store layer — keep non-escaping local vectors and keyed tables out of store records where escape analysis proves they stay inside the frame.
- Calls without the runtime context on pure functions — the compiler tracks function purity, and pure C functions that never touch heap stores can omit the runtime context parameter once gated by a store-effect classifier.
- Unchecked integer arithmetic — where operands are proven non-null and within bounds outside loop index chains, emit plain C arithmetic.
- In-place text appends and bulk slice copies — extend the twin-buffer append rewrite to text-returning functions and block-copy primitive vector slices.
- wasm string layout — a text representation for the WASI and browser targets that reduces linear-memory reallocation traffic on text building.