lua-users home
lua-l archive

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


Alexander Gladysh wrote:
> 2. Plain C version in LuaJIT is slower than specialized 'generated'
> one in plain Lua, but still faster than any of generic versions.

Not surprising, since the Lua/C API transitions add some cost. And
a general rule for VMs with JIT compilers is NOT to rewrite your
code in C because the compiler cannot optimize "into" C functions.

This applies even more so to LuaJIT 2.x: calling an "unknown" C
function inside a loop effectively disables JIT compilation for
this loop. Here "unknown" means the JIT compiler has no idea about
its potential side-effects (note that most of the standard library
functions are of course "known" to the compiler).

But falling back to the interpreter is not so bad, since it's
pretty fast (around the speed of LuaJIT 1.x). The "C" test takes
2.87s on a Core2 @ 2.13 GHz.

All other tests run (or should run [*]) in around 0.0047s. :-)

This is because everything can be hoisted out of the loop. The
loop itself runs at 1 cycle/iteration, i.e. maximum CPU speed.
The perils of microbenchmarking ...

[*] Not all of them can be compiled (yet). Sorry, still no ETA.

--Mike