[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luajit ffi - calling a luajit function via a C function pointer?
- From: Leo Razoumov <slonik.az@...>
- Date: Thu, 10 Feb 2011 19:27:23 -0500
On Thu, Feb 10, 2011 at 12:53, Mike Pall <mikelu-1102@mike.de> wrote:
> Leo Razoumov wrote:
>> When one calls back from C into Lua using conventional lua_call(...)
>> does LuaJIT2 traces and optimizes the lua function call?
>
> The problem is with the Lua/C API, the overhead is in the API
> itself, not in any Lua code. The C to Lua transition is even more
> costly than the Lua to C transition. I can't change the Lua C/API,
> but you can stop using it.
>
> In other words: don't do this in performance sensitive parts of
> your applications. Write everything in Lua. And if you must, then
> put C functionality in libraries callable from the FFI.
>
> --Mike
>
C functionality I need is already inside a C library, but in order to
calculate a quadrature (definite integral) the C function takes a
callback which is a wrapper around a Lua function. Call chain becomes
essentially Lua->C->Lua and one of the Lua functions is inside a tight
loop.
One way to avoid C<->Lua transitions is to re-implement large portions
of the numeric C library in pure Lua. This is, indeed, possible but
not practical, for it takes lots of time implementing/optimizing and,
above all, testing the code. In numerics people are still using
packages from 70-s (Fortran) and are quite happy with them.
I am probably asking for too much, but is it possible to call into Lua
without explicit stack manipulations at least for some simple calling
conventions?
--Leo--