Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference in the way Lua and LuaJIT process the code?

Tags:

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?

like image 361
user6245072 Avatar asked Mar 02 '17 22:03

user6245072


People also ask

What is the difference between Lua and LuaJIT?

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.

Is LuaJIT faster than Lua?

Performance. LuaJIT is often the fastest Lua runtime. LuaJIT has also been named the fastest implementation of a dynamic programming language.

What Lua version is LuaJIT?

LuaJIT is compatible to the Lua 5.1 language standard.

How is LuaJIT so fast?

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.


1 Answers

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.

like image 165
Paul Kulchenko Avatar answered Sep 25 '22 10:09

Paul Kulchenko