[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LuaJIT FFI callbacks for functions using only built-in operators and locals
- From: Adam Strzelecki <ono@...>
- Date: Thu, 15 Dec 2011 23:48:26 +0100
>> Having that such function use only built-in operators, locals
>> and single types across whole body, could it be optimized
>> straight ahead into machine code?
> It would be possible to reduce the marshaling overhead with a lot
> of effort. But there's no easy way to avoid the cost for entering
> and leaving the VM in general. And that makes up the majority of
> the overhead.
Forgive my ignorance, I may be telling here total nonsense, but I am just thinking about specific case where function does use only built in operators (that cannot be overloaded) and do not modify global environment. Once the initial trace is completed, VM could just make single "jmp" under original function address to function machine code, omitting VM enter & leave since the function does not touch global state anyway and does not call any other functions that can cause such state change.
Of course I have absolutely no idea whether it is possible to determine whether code block (function) does not modify global context, so it can be run out of the Lua state. Also probably implementation effort of functionality would be just an overkill.
> That's a dead end, as I've described in the FFI docs. Don't use
> callbacks if you care about performance.
Yeah I've read that. I have let myself to ask about these FFI callbacks just because use levmar library for one project. Levmar requires callback that returns current minimalisation and Jacobian matrix, and these are called quite frequently during whole optimization process. On other side Levmar package could be rewritten into Lua itself similar to what Francesco done with GSL Shell. But probably I am just too lazy to do that ;P