Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the trade offs between ffi and mri c extensions in ruby?

Tags:

ruby

ffi

What are the trade offs between ffi and mri c extensions in ruby?

like image 856
jshen Avatar asked Feb 27 '23 06:02

jshen


2 Answers

One obvious tradeoff is that MRI C extensions only work on MRI, whereas FFI extensions work on MRI, YARV, Rubinius and JRuby at the moment, and will in the future probably also work on IronRuby, MagLev, MacRuby, SmallRuby, tinyrb and RubyGoLightly.

like image 89
Jörg W Mittag Avatar answered Apr 20 '23 01:04

Jörg W Mittag


ffi is a tidge slower for method call invocation. Also ffi can't use any "native C" code unless you combine it with compilation, for example with ffi-inliner.

ffi is much more cross-VM friendly.

like image 42
rogerdpack Avatar answered Apr 19 '23 23:04

rogerdpack