lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2009/11/2 Mike Pall <mikelu-0911@mike.de>:
> No, if you repeatedly call a 'flat' Lua function from C. I.e. if
> the inner loop is on the C side and the Lua side is just a short
> non-looping callback (like the comparison function of table.sort).

Unfortunately this is actually the case of my code, a simple Lua
function called over and over from a library C code. I guees I will
have to wait for LuaJIT 3 :-)

> But you have to realize that context switches between C and Lua
> are costly, that nothing can be hoisted out of such a trace and
> that the compiler cannot optimize the C side and the Lua side
> together.
>
> You are going to get much better performance if you stay on the
> Lua side for as long as possible. This also applies to upcalls
> to C functions: avoid them in inner loops written in Lua.

I understand but unfortunately to have everything in Lua for me would
mean to rewrite some large and complex, optimised C routines. In
particular I'm talking about GSL routines for ODE integration. I don't
think I'm not going to rewrite them in Lua :-)

thank you very much anyway for the clarifications!

Francesco