lua-users home
lua-l archive

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


steve donovan wrote:
> John C. Turnbull wrote:
> > Does anyone know of a Java wrapper for LuaJIT?  I am looking for the absolute fastest way to script my Java apps.
> 
> I haven't tried it, but you should be able to build LuaJava against
> LuaJIT, the external API is just the same.

Please note that LuaJava uses JNI for calls from Java to Lua or
back from Lua into Java. It's well known that JNI is *slow*. And
LuaJava also has to serialize/unserialize all values passed across
the Lua/Java boundary.

Neither Java's JIT compiler, not LuaJIT will be able to speed this
process up. The more often you cross the language boundary, the
more performance loss this incurs. E.g. repeatedly calling a Lua
method from inside a Java loop (or vice versa) is a bad idea.
Alas, this more or less rules out many good use cases for
scripting a Java application.

You really need to stay in *either* the Java domain *or* the Lua
domain for as long as possible. A long running loop in pure Lua
will definitely benefit from the use of LuaJIT. But if you're just
running a couple of instructions on either side, you're not going
to see much of a difference. So, please don't be disappointed of
the results.

If you have a large Java code base, it may be a better choice to
look for a scripting language which stays inside the Java domain
(i.e. generates Java classes at runtime) and thus doesn't have to
use JNI.

[Note that this is not a critique of either LuaJava or JNI. The
use of JNI is a design decision of LuaJava. And the performance of
JNI simply reflects the inherent impedance mismatch between the
Java and the C side.]

--Mike