Peter Cawley wrote:
Along the same lines, I noticed that in a recent project, most of my
C(++) glue functions did very simple things - read some values off the
Lua stack, call some C++ method, and push the results back onto the
stack. It seems to me rather wasteful for LuaJIT to setup a stack,
call my C(++) function, have that call back to the API to read/write
values, then have LuaJIT tear the stack down again.
Yes, now that everything else has gotten so fast, that's the main
performance bottleneck when calling C functions from compiled Lua
code. And it gets worse: the compiler can't optimize across such
calls, because they might have arbitrary side-effects (changing a
global, growing/reallocating a table etc.).