LuaJIT

Last updated
LuaJIT
Original author(s) Mike Pall
Stable release
v2.1.ROLLING [1] / August 21, 2023;2 years ago (2023-08-21)
Repository github.com/LuaJIT/LuaJIT
Written in C, Lua
Operating system Unix-like, MacOS, Windows, iOS, Android, PlayStation
Platform x86, x86-64, PowerPC, ARM, MIPS [2]
Type Just-in-time compiler
License MIT License [3]
Website luajit.org

LuaJIT is a tracing just-in-time compiler and interpreter for the Lua programming language.

Contents

History

The LuaJIT project was started in 2005 by developer Mike Pall, released under the MIT open source license. [4]

The second major release of the compiler, 2.0.0, featured major performance increases. [5]

LuaJIT uses rolling releases. Mike Pall, the creator and maintainer recommends using the tip of the v2.1 branch, and does not believe in releases. [6]

Mike Pall resigned in 2015 making only occasional patching to the future 2.1 version since then. [7]

Notable users

Performance

LuaJIT is often the fastest Lua runtime. [13] LuaJIT has also been named the fastest implementation of a dynamic programming language. [14] [15]

LuaJIT includes a Foreign Function Interface compatible with C data structures. Its use is encouraged for numerical computation. [16]

Tracing

LuaJIT is a tracing just-in-time compiler. LuaJIT chooses loops and function calls as trace anchors to begin recording possible hot paths. Function calls will require twice as many invocations to begin recording as a loop. Once LuaJIT begins recording, all control flow, including jumps and calls, are inlined to form a linear trace. All executed bytecode instructions are stored and incrementally converted into LuaJIT's static single-assignment intermediate representation. LuaJIT's trace compiler is often capable of inlining and removing dispatches from object orientation, operators, and type modifications. [17]

Internal representation

LuaJIT uses two types of internal representation. A stack-based bytecode is used for the interpreter, and a static single-assignment form is used for the just-in-time compiler. The interpreter bytecode is frequently patched by the JIT compiler, often to begin executing a compiled trace or to mark a segment of bytecode for causing too many trace aborts. [15]

-- Loop with if-statementlocalx=0fori=1,1e4dox=x+11ifi%10==0then-- if-statementx=x+22endx=x+33end
---- TRACE 1 start Ex.lua:5---- TRACE 1 IR0001 int SLOAD #2 CI0002 > num SLOAD #1 T0003 num ADD 0002 +110004 int MOD 0001 +100005 > int NE 0004 +00006 + num ADD 0003 +330007 + int ADD 0001 +10008 > int LE 0007 +100000009 ------ LOOP ------------0010 num ADD 0006 +110011 int MOD 0007 +100012 > int NE 0011 +00013 + num ADD 0010 +330014 + int ADD 0007 +10015 > int LE 0014 +100000016 int PHI 0007 00140017 num PHI 0006 0013---- TRACE 1 stop -> loop---- TRACE 2 start 1/4 Ex.lua:8---- TRACE 2 IR0001 num SLOAD #1 PI0002 int SLOAD #2 PI0003 num ADD 0001 +220004 num ADD 0003 +330005 int ADD 0002 +10006 > int LE 0005 +100000007 num CONV 0005 num.int---- TRACE 2 stop -> 1

Extensions

LuaJIT adds several extensions to its base implementation, Lua 5.1, most of which do not break compatibility. [18]

DynASM

DynASM
Developer(s) Mike Pall
Repository
Written in Lua, C [23]
Platform x86, X86-64, PowerPC, ARM, MIPS
Type Preprocessor, Linker
License MIT License [3]
Website luajit.org/dynasm.html

DynASM is a lightweight preprocessor for C that provides its own flavor of inline assembler, independent of the C compiler. DynASM replaces assembly code in C files with runtime writes to a 'code buffer', such that a developer may generate and then evoke code at runtime from a C program. It was created for LuaJIT 1.0.0 to make developing the just-in-time compiler easier.[ citation needed ]

DynASM includes a bare-bones C header file which is used at compile time for logic the preprocessor generates. The actual preprocessor is written in Lua.

References

  1. LuaJIT tags
  2. "LuaJIT". LuaJIT. Retrieved 25 February 2022.
  3. 1 2 "LuaJIT/COPYRIGHT at v2.1 · LuaJIT/LuaJIT". GitHub . 7 January 2022.
  4. "The LuaJIT Project". luajit.org. Retrieved 2023-06-17.
  5. Pall, Mike. "Re: [ANN] llvm-lua 1.0". lua-users.org. Retrieved 25 February 2022.
  6. "Project status - Issue #665 - LuaJIT/LuaJIT". GitHub. Retrieved 3 February 2023.
  7. "[ANN] Looking for new LuaJIT maintainers - luajit - FreeLists". www.freelists.org. Retrieved 2023-03-29.
  8. Deniau, Laurent. "Lua(Jit) for computing accelerator beam physics". CERN Document Server. CERN. Retrieved 25 February 2022.
  9. "OpenResty® - Official Site". openresty.org.
  10. "Lua - Neovim docs". neovim.io. Retrieved 2024-05-07.
  11. "Kong/kong". GitHub. Kong. 25 February 2022. Retrieved 25 February 2022.
  12. "Helping to make Luajit faster". blog.cloudflare.com. 19 October 2017. Retrieved 25 February 2022.
  13. "LuaJIT Performance".
  14. "Laurence Tratt: The Impact of Meta-Tracing on VM Design and Implementation". tratt.net. Retrieved 2 March 2022.
  15. 1 2 d'Andrea, Laurent (2019). Behavioural Analysis of Tracing JIT Compiler Embedded in the Methodical Accelerator Design Software (Thesis). CERN. Retrieved 31 July 2022.
  16. Pall, Mike. "Tuning numerical computations for LuaJIT (was Re: [ANN] Sci-1.0-beta1) - luajit - FreeLists". www.freelists.org.
  17. Rottenkolber, Max. "Later Binding: Just-in-Time Compilation of a Younger Dynamic Programming Language." ELS. 2020
  18. "Extensions". LuaJIT. Retrieved 25 February 2022.
  19. "BitOp Semantics". LuaJIT. Retrieved 25 February 2022.
  20. "Coco - True C Coroutines". LuaJIT. Retrieved 25 February 2022.
  21. "FFI Library". LuaJIT. Retrieved 25 February 2022.
  22. "Extensions". luajit.org. Retrieved 2022-08-25.
  23. "DynASM Features". DynASM. Retrieved 25 February 2022.