[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: luaffi/luaffi question: Calling c function ptr possible?
- From: Javier Guerra Giraldez <javier@...>
- Date: Fri, 10 Jul 2015 12:30:18 -0500
On Fri, Jul 10, 2015 at 12:07 PM, Tom N Harris <firstname.lastname@example.org> wrote:
> FFI isn't just an extra dependency for you to carry, it's also very, very slow
> unless you're using LuaJIT.
a very rough speed ranking of Lua->C interfacing methods, from fastest
1.- LuaJIT, fully compiled FFI
2.- LuaJIT, Lua C API
3.- PUC Lua, Lua C API
4.- LuaJIT, intepreted FFI
5.- any Lua, luaffi module
- even better than 1: don't use C. it's faster to do tight loops in
fully compiled Lua code than to call C code for small things.
- big (several orders of magnitude) difference from 1 to 2
- 2 and 3 are roughly similar. an interesting data point is the Redis
server. It can use LuaJIT, but there's very small performance
advantage (the author cites around 10%)
- very perceptible difference from 3 to 4 (that's why under LuaJIT you
shouldn't use the FFI in tight loops if you're not sure this inner
code is compiled)
- i haven't personally benchmarked the luaffi module (case 5), but
it's a pretty heavy wrapping on top of the Lua C API, so it's
noticeably slower than 3. the 4 case does much of the same, but in
the core of the LuaJIT interpreter (which is quite fast, in fact)
instead of the C API, so it has a significant advantage over 5. my
feeling is that the difference from 4 to 5 is similar to the one from
3 to 4.