lua-users home
lua-l archive

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


I think it can produce faster code than "C" in situations where more
information is available at runtime, but not compile time.

Typical example is calling virtual function (C++), or through a
function pointer (C/C+). With JIT this code can be inlined at runtime.

Also if you have many logical branches in given function, yet for some
set of parameters only few of the branches are taken, and the function
happens to be called more frequently with these parameters, then again
it could be optmized better at runtime, than compile time.

I guess it's a hard balance, because the compile time in JIT is taken
as run-time, so there must be some tradeoff, but so far what I've seen
from LuaJIT (2.0.0+ versions) is simply stunning.

I can't understand 1% of the code that Mike Pall has written, because
I don't have any knowledge in that area - but whatever he did is
simply amazing.

I've actually had cases where LuaJIT was beating "C" code in my
benchmarks. Have to find it.


On Sun, Aug 29, 2010 at 3:01 PM, Joe Finn <warriorjoe118@gmail.com> wrote:
> Based on my experience with Java JIT, and without detailed knowledge of Lua
> JIT, I think the JIT probably produces much less efficient code than the C
> compiler for the same "script". That's just the nature of JITs -- they don't
> have a lot of time to do their job, the user is waiting while they compile,
> so they must be **FAST**. I'd be very surprised if the Lua JIT produces code
> that's more efficient than what a C compiler produces at -O2 or even -O1.
> There's usually a 3X improvement for cpu-bound algorithms going from -O1 to
> -O4 so that means that highly optimized C code can be (at least) four times
> faster than an equivalent JIT-ed Lua program.
>
> Add to that the need for the Lua JIT-ed program to support introspection and
> the overhead of the data types of Lua versus the much simpler data types
> that are primitives in C, and I wouldn't be surprised for specific programs
> to see compiled C code be 10x more efficient (both space and time-wise) than
> an equivalent Lua program when running on a JIT.
>
> --Joe
>
> On Sun, Aug 29, 2010 at 2:52 PM, Patrick McCavery <patrick@cakeandfile.com>
> wrote:
>>
>> I know many many people are writing applications as a mix of Lua and C but
>> I am wondering if this is becoming more unnecessary now that we have LuaJit,
>> which is pretty bloody fast.
>>
>> I know Lua can't be used in kernel space and that without C there would be
>> few libraries, are there any other reasons why why LuaJit could not be used
>> in place of C?
>>
>> --Patrick
>>
>
>



-- 
Dimiter "malkia" Stanev,
ICQ: 21875894
malkia@mac.com
malkia@gmail.com