Lua JIT (Just in Time Compiler)
Mientras sigo jugando con otras cosas (RoR en concreto y algunas más) me he encontrado con esto en la lista de Lua. LuaJIT es un traductor dinámico al vuelo de lua a ensamblador nativo, lo que hace es sustituir las funciones en lua por código equivalente x86 según se va necesitando. No es un concepto nuevo (C#, Psyco, Java-jit…) pero me resulta curioso que alguien invierta esfuerzos en un lenguaje de scripting como lua a estos niveles.
Como nota curiosa los speedups que consiguen van desde 1.04 a 7.79 (casi 8 veces más rápido que código normal lua), frente a otros como psyco (python) que va de 2 a 100. Supongiendo que luaJIT está bien hecho (cosa que me parece más que probable) el hecho de que se consigan speedups «bajos» dice mucho a favor de la velocidad de Lua por si mismo.
Más info sobre JIT en la Wikipedia(JIT)
Yes, the Lua interpreter is already very fast. But this is only part of the reason why the LuaJIT speedups are ‘conservative’.
The published speedups come from ‘real’ benchmarks and not from some micro benchmarks (usually one-liners). I can easily come up with several micro ‘benchmarks’ that show a 30x speedup with LuaJIT. But I regard this as dishonest.
Telling people they won’t see a speedup if they mainly use C library calls (i.e. the 1.04x figure) is maybe bad marketing, but also something they need to consider.
For a real cross-language comparison look at http://shootout.alioth.debian.org/ and at http://shootout.alioth.debian.org/gp4/ . Please note that Lua gets its speed without using tons of calls to C functions (like Python does) and still beats Python and Perl easily. Then compare Lua to Psyco (only in the gp4 set) and you’ll be enlightened.
LuaJIT is not in there (yet), but would score significantly higher on the pure CPU benchmark score (change the weights to 1, 0, 0 in the form). Somewhere around the Java scores (JIT compiled Java, not the Java interpreter).
E.g. LuaJIT 1.0.3 gets around 50% of the speed of fully-optimized and hand-tuned C code in the mandelbrot benchmark. That’s not so bad for a JIT engine that fits in only 25 Kilobytes IMHO.
I wonder if it is theoretically possible to use the same techniques used in LuaJit to speed up python.
Is there any chance to reuse this jit (or part of it) for implementing other languages?