From what I understood, the standard Lua interpreter first compiles the input code to "bytecode" (the output of luac
) and then "interpretes" that bytecode.
But isn't that basically the definition of a JIT compiler? What does LuaJIT do then? How does it differ from the standard Lua interpreter? How can it be this faster?
LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language. Lua is a powerful, dynamic and light-weight programming language. It may be embedded or used as a general-purpose, stand-alone language.
Performance. LuaJIT is often the fastest Lua runtime. LuaJIT has also been named the fastest implementation of a dynamic programming language.
LuaJIT is compatible to the Lua 5.1 language standard.
LuaJIT uses advanced compilation techniques, and it also has a very finely engineered implementation. For example, when the fancy compilation techniques can't handle a piece of code, LuaJIT falls back to an very fast interpreter written in x86 assembly.
isn't that basically the definition of a JIT compiler? What does LuaJIT do then?
It implements its own interpreter, which is often faster than the "standard" Lua interpreter and it JIT-compiles frequently visited fragments to machine instructions, which brings further performance gains, but limits the portability (as those instructions are machine/architecture-specific).
There are many more improvements and optimizations, which you can find in Mike Pall's overview. Also see this page for the overall JIT discussion and specifically Mike Pall's comments on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With