4 ms·
I think the whole idea behind using Julia in this situation would be that you get good enough performance "out of the box" so that you don't have to resort to u
by chroem- 9y ago
I think the whole idea behind using Julia in this situation would be that you get good enough performance "out of the box" so that you don't have to resort to using an FFI in the first place.
- vvanders 9y agoBut that's also the brilliance of Rust supporting a clean C ABI. I can write in anything I want since every language supports C ABI for system calls. I don't want to have to learn a whole new language and new API at the same time. Also a cursory glance at Julia's numpy support looks like it requires deep copies which is painful when you want things to be fast. I'm sure it's a great language but needing to drag in a whole new VM means it doesn't fit my needs.
- gravypod 9y agoJulia is jit compiled by llvm to your native machine code. Correctly written Julia is within 1.5 the speed of C. It removes the complexity of needing to do the FFI at all.
- deleted 9y ago[deleted]
- vvanders 9y agoYou make it sound like ffi is a nasty 3 letter word ;). It look me 3 lines of code to import the dll, assign the signature and call the function, I'd hardly call that complex.
- mlevental 9y agothis is probably a dumb question but did you just compile the rust binary and then expose the functions? how? I don't remember but does rust face header files?
- vvanders 9y agoYup, just declare the function like so: #[no_mangle] pub unsafe extern "C" fn transform_pcm( data: *mut c_short, len: c_uint, ramp_time: c_uint, tone_delta_frame: c_float) { then call from python: gen_pcm_dll = ctypes.cdll.LoadLibrary("gen_pcm_rust/target/release/gen_pcm.dll") gen_pcm_dll.transform_pcm.argtypes = [ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_float] gen_pcm_dll.transform_pcm(ptr, len(pcm), ramp_time, tone_delta_frame) Rust doesn't generate headers(although there are helper libs if you want) and you don't need them to FFI.
- the_mitsuhiko 9y agoHere is how we do it: https://blog.sentry.io/2017/11/14/evolving-our-rust-with-milksnake https://blog.sentry.io/2017/11/14/evolving-our-rust-with-mil...
- one-more-minute 9y agoThis is fine for new projects, but OP already has a large Ruby codebase. "Just rewrite the whole thing in Julia and you won't need FFI" isn't a reasonable ask. Rust's ability to compile to a small C-compatible binary is definitely an advantage here, although Julia will have similar capabilities soon.
- jamii 9y ago> although Julia will have similar capabilities soon. Do you have a link to further info on that?
- one-more-minute 9y agoSee https://github.com/JuliaComputing/static-julia https://github.com/JuliaComputing/static-julia A lot of this stuff has worked for ages, but it's rough in various places and needs a better interface. I'm not sure to what extent exporting C functions is actually supported in that wrapper script, or whether you'll need to fiddle with compiler options.
- coldtea 9y agoNo, but you would have to do with subpar/immature third party ecosystem AND you'd have to port all your Python code to Julia before you can get to resort entirely to it.