4 ms·
http://luajit.org/ext_ffi.html http://luajit.org/ext_ffi.html
by based2 8y ago
http://luajit.org/ext_ffi.html http://luajit.org/ext_ffi.html
- ksec 8y agoIt is like decade after Mike Pall show the world LuaJit and FFI, he is still schooling everyone. It is very sad he left Reddit, HN and almost every other online communities along with LuaJIT. Edit: Sorry I was wrong. Looks like he is still working on LuaJIT!
- ndesaulniers 8y agoThanks for the link. From this hn post, I'm baffled at how any other language could beat c at c ffi. (Hopefully your article explains how. Reading it now).
- gravypod 8y agoAm I getting this right? Is LuaJIT inlining linked assembly into the program at runtime? That's amazing.
- ndesaulniers 8y agoThat was my takeaway, but not sure to what extent. You could then do peephole optimization after. You'd lose out on the memory saving from shared objects, but that's a trade-off I'm cool with.
- fpgaminer 8y agoNot sure if LuaJIT will do that, but it's not doing that here. LuaJIT is calling the library just like normal. See my and glandium's comment thread. TL;DR: LuaJIT's trick is that it avoids the linkage table.
- ufo 8y agoInlining assembly at runtime is what JITs do.
- BeeOnRope 8y agoNo, it is not. It still makes a call to the method in the shared object, it's just the way this call is made is more efficient than C. "Inlinig" compiled assembly from a shared object is basically impossible because you can't just move machine code around arbitrary since it may access arbitrary additional code or data at relative offsets. If you move it, you'll break it.
- Erwin 8y agoThe Python "cffi" module (one of the many possible ways to do FFI in Python) works in a similar way: https://cffi.readthedocs.io/en/latest/overview.html#simple-example-abi-level-in-line https://cffi.readthedocs.io/en/latest/overview.html#simple-e...