Tiny JITs for a Faster FFI

The author explores the idea of creating a faster FFI for CRuby by leveraging YJIT optimizations. By comparing benchmarks between FFI, C extensions, and Ruby methods, it is evident that direct calls to Ruby methods are the fastest. The author introduces a proof of concept called “FJIT,” which generates machine code at runtime to call foreign functions. Surprisingly, the machine code generated by FJIT is faster than the C extension and significantly faster than FFI. This innovative approach could potentially allow Ruby to achieve speeds comparable to C extensions while maintaining a focus on writing Ruby code. Although there are some limitations, the prospect is promising for the future of Ruby development.

https://railsatscale.com/2025-02-12-tiny-jits-for-a-faster-ffi/

To top