module Rubellite::Docs::B_ADVANCED_FEATURES::SPINEL_AOT

Overview

Spinel AOT Native Compilation Fast-Path

Spinel is Rubellite's native code generation and fast-path execution engine. For tight loops, mathematical simulations, and cryptographic routines, Spinel bypasses the standard Ruby YARV bytecode interpreter, compiling native LLVM machine code callable directly from either Crystal or Ruby.

Executive Summary & Key Topics

Topic Method / Anchor Description
Spinel Kernel Compilation .topic_01_spinel_compilation Authoring and compiling native C/LLVM kernels for 10x-50x speedups.

Related Guides & Source References

Defined in:

rubellite/docs/b_advanced_features/spinel_aot.cr

Class Method Summary

Class Method Detail

def self.topic_01_spinel_compilation : Nil #

Spinel Kernel Compilation: Authoring and compiling native C/LLVM kernels for 10x-50x speedups.

Spinel supports compiling native C algorithms into shared dynamic libraries loaded at runtime:

Feature Standard Ruby Spinel AOT Fast-Path
**Execution** YARV Bytecode / JIT Native LLVM Machine Code
**Boxing Overhead** Object allocation Zero unboxed scalar math
**Speedup** Baseline 1.0x 10x - 50x for numerical kernels

Working Examples

require "rubellite"

# Compile a native Fibonacci function via Spinel
kernel = Rubellite::Spinel.compile_c(<<-C)
  long long fib(long long n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
  }
C

res = kernel.call("fib", 35_i64)
puts "Fib(35): #{res}"

Common Pitfalls & Safety Caveats

  • Warning: Spinel requires an available C compiler (clang, gcc, or MSVC cl.exe) when compiling dynamic kernels on the fly.

Frequently Asked Questions (FAQ)

  • Q: What happens if a native C compiler is not found? A: Rubellite falls back gracefully to pure Crystal or Ruby interpreted implementations.

[View source]