
April 27, 2026
Shortly after RubyKaigi 2026, I came across Spinel, an experimental Ruby compiler that takes a markedly different approach to performance.
Spinel is an ahead-of-time (AOT) compiler for Ruby. Instead of executing code through a virtual machine, it compiles Ruby source into optimized C, and from there into a standalone native executable. The result is a binary that runs without any Ruby runtime or interpreter dependency.
At a high level, the compilation pipeline is simple:
- Ruby source code is parsed into an AST (using Prism)
- The program undergoes whole-program type inference
- Optimized C code is generated
- A standard C compiler produces the final binary
This design allows Spinel to apply aggressive optimizations that are not typically possible in a dynamic runtime environment.
What Makes Spinel Interesting
The most notable aspect of Spinel is its use of global type inference. By analyzing the entire program ahead of time, it can eliminate a large portion of Ruby’s dynamic overhead. This enables:
- Inlining of small methods
- Constant propagation
- Elimination or reduction of garbage collection in certain cases
- Stack allocation of small objects (value-type promotion)
In practice, this translates into substantial performance gains in computation-heavy workloads often an order of magnitude faster than CRuby in benchmark scenarios.
Another important detail is that Spinel is self-hosting. The compiler backend itself is written in a restricted subset of Ruby and compiled by Spinel. This is a strong signal of internal consistency and maturity in its design.
Trade-offs and Constraints
Spinel achieves its performance by narrowing the scope of supported Ruby features. It intentionally excludes parts of the language that depend on runtime dynamism, such as:
- eval and runtime code generation
- method_missing and heavy metaprogramming
- Threads and certain concurrency primitives
As a result, it is not a drop-in replacement for general-purpose Ruby applications, particularly frameworks like Rails that rely heavily on metaprogramming.
Instead, Spinel is better understood as a statically analyzable subset of Ruby, optimized for predictability and performance.
Why It Matters
Spinel represents a different philosophy within the Ruby ecosystem. While efforts like YJIT focus on making the interpreter faster, Spinel explores what Ruby looks like when you shift work entirely to compile time.
This raises interesting possibilities:
- Writing high-performance CLI tools in Ruby
- Shipping standalone binaries without runtime dependencies
- Exploring a more static, analyzable subset of the language
Even if it remains experimental, Spinel contributes to a broader conversation about how far Ruby can evolve beyond its traditional execution model.
