[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Native Complex numbers for LuaJIT-2 [was Re: Benchmark shootout shows LuaJIT 2.0]
- From: Mike Pall <mikelu-0911@...>
- Date: Mon, 2 Nov 2009 16:23:12 +0100
Francesco Abbate wrote:
> I was wondering if the JIT compiler is also able
> to optimise Lua functions called with 'lua_call' from within a C
> library code (called, in turn, from Lua top level).
Yes, if that Lua function contains a loop.
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).
The Lua part of the latter variant could be compiled as a
non-looping trace. This is probably going to be added when I add
tracing of recursion, because it needs similar support code.
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
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.