Spinel: Ruby AOT Native Compiler

Spinel is a self-hosting Ruby compiler that transforms source code into standalone native executables, achieving an average 11.6x speedup over CRuby through whole-program type inference and optimized C generation.
Spinel compiles Ruby source code into standalone native executables. It performs whole-program type inference and generates optimized C code, achieving significant speedups over CRuby.
Spinel is self-hosting: the compiler backend is written in Ruby and compiles itself into a native binary.
Workflow
Ruby (.rb) -> spinel_parse (Prism) -> AST -> spinel_codegen -> C source (.c) -> cc -O2 -> Native binary
Performance Benchmarks
Geometric mean: ~11.6x faster than miniruby (Ruby 4.1.0dev).
| Benchmark | Spinel | miniruby | Speedup | |---|---|---|---| | life (Conway's GoL) | 20 ms | 1,733 ms | 86.7x | | ackermann | 5 ms | 374 ms | 74.8x | | mandelbrot | 25 ms | 1,453 ms | 58.1x | | fib (recursive) | 17 ms | 581 ms | 34.2x |
Key Features
- Core: Classes, inheritance, mixins, open classes.
- Control Flow: Pattern matching, loops, exceptions (rescue/ensure).
- Types: Bigint (auto-promoted), Fiber (ucontext_t), Array, Hash.
- Memory: Mark-and-sweep GC, stack-allocation for small immutable classes (value types).
- Optimizations: Method inlining, constant propagation, string concat flattening, and dead-code elimination.
Source: Hacker News
















