Faster FFI For Ruby
summary
Claims a JIT-driven FFI can beat C by compiling type-specific trampolines and smuggling metadata into native code; implements a pure-Ruby prototype FJIT that generates ARM64 machine code and a toolchain FFX that emits C extensions with JIT hints for Zjit. Benchmarks show FFI ~15M iters/s, C extension ~45M, and FFX+Zjit ~54M iterations per second (SQLite and strlen examples), and the generated wrappers run successfully though the prototype supports only a few types.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:58What is FFI
- 5:11Use FFI or not
- 6:56FFI call overhead
- 8:40Ruby C extension calls
- 13:38Why FFI is slower
- 15:25JIT for FFI slowness
- 16:28FJIT and benchmarks
- 20:42FJIT limitations
- 22:31Built-in faster FFI
- 24:15FFX generates C
- 26:00JIT hints and smuggling
- 28:50ZJIT hints usage
- 30:18Benchmark FFX vs FFI vs C
- 31:44SQLite example
- 32:51Future improvements
- 33:11Summary and Q&A








