LuaJIT

Last updated
LuaJIT
Original author(s) Mike Pall
Stable release
2.0.5 (later v2.1.ROLLING is also updated, e.g. in 2023) / May 1, 2017;7 years ago (2017-05-01)
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 [1]
Type Just-in-time compiler
License MIT License [2]
Website luajit.org

LuaJIT is a tracing just-in-time compiler for the Lua programming language. Mike Pall, a primary maintainer of the project had resigned in 2015, resorting only to occasional patching to the future 2.1 version. [3]

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]

The latest release, 2.0.5 is released in 2017. However, Mike Pall, the creator and maintainer recommends using the tip of the v2.1 branch, and does not believe in releases. [6]

Notable users

Performance

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

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

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. [16]

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. [14]

-- 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. [17]

DynASM

DynASM
Developer(s) Mike Pall
Repository
Written in Lua, C [22]
Platform x86, X86-64, PowerPC, ARM, MIPS
Type Preprocessor, Linker
License MIT License [2]
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.

Related Research Articles

<span class="mw-page-title-main">Java virtual machine</span> Virtual machine that runs Java programs

A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.

<span class="mw-page-title-main">Vim (text editor)</span> Improved version of the Vi keyboard-oriented text editor

Vim is a free and open-source, screen-based text editor program. It is an improved clone of Bill Joy's vi. Vim's author, Bram Moolenaar, derived Vim from a port of the Stevie editor for Amiga and released a version to the public in 1991. Vim is designed for use both from a command-line interface and as a standalone application in a graphical user interface. Since its release for the Amiga, cross-platform development has made it available on many other systems. In 2018, it was voted the most popular editor amongst Linux Journal readers; in 2015 the Stack Overflow developer survey found it to be the third most popular text editor, and in 2019 the fifth most popular development environment.

OCaml is a general-purpose, high-level, multi-paradigm programming language which extends the Caml dialect of ML with object-oriented features. OCaml was created in 1996 by Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy, Ascánder Suárez, and others.

Common Intermediate Language (CIL), formerly called Microsoft Intermediate Language (MSIL) or Intermediate Language (IL), is the intermediate language binary instruction set defined within the Common Language Infrastructure (CLI) specification. CIL instructions are executed by a CIL-compatible runtime environment such as the Common Language Runtime. Languages which target the CLI compile to CIL. CIL is object-oriented, stack-based bytecode. Runtimes typically just-in-time compile CIL instructions into native code.

<span class="mw-page-title-main">Lua (programming language)</span> Lightweight programming language

Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is written in ANSI C, and Lua has a relatively simple C API to embed it into applications.

<span class="mw-page-title-main">Interpreter (computing)</span> Program that executes source code without a separate compilation step

In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  1. Parse the source code and perform its behavior directly;
  2. Translate source code into some efficient intermediate representation or object code and immediately execute that;
  3. Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter's Virtual Machine.

Bytecode is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references that encode the result of compiler parsing and performing semantic analysis of things like type, scope, and nesting depths of program objects.

<span class="mw-page-title-main">SpiderMonkey</span> JavaScript and WebAssembly engine maintained by the Mozilla Foundation

SpiderMonkey is an open-source JavaScript and WebAssembly engine by the Mozilla Foundation.

In computing, just-in-time (JIT) compilation is compilation during execution of a program rather than before execution. This may consist of source code translation but is more commonly bytecode translation to machine code, which is then executed directly. A system implementing a JIT compiler typically continuously analyses the code being executed and identifies parts of the code where the speedup gained from compilation or recompilation would outweigh the overhead of compiling that code.

In software engineering, profiling is a form of dynamic program analysis that measures, for example, the space (memory) or time complexity of a program, the usage of particular instructions, or the frequency and duration of function calls. Most commonly, profiling information serves to aid program optimization, and more specifically, performance engineering.

<span class="mw-page-title-main">C Sharp (programming language)</span> Programming language

C# is a general-purpose high-level programming language supporting multiple paradigms. C# encompasses static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines.

<span class="mw-page-title-main">PyPy</span> Alternative implementation of the Python programming language

PyPy is an implementation of the Python programming language. PyPy often runs faster than the standard implementation CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPython extensions, which either does not work or incurs some overhead when run in PyPy.

Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under the MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.

The Berkeley Packet Filter is a network tap and packet filter which permits computer network packets to be captured and filtered at the operating system level. It provides a raw interface to data link layers, permitting raw link-layer packets to be sent and received, and allows a userspace process to supply a filter program that specifies which packets it wants to receive. For example, a tcpdump process may want to receive only packets that initiate a TCP connection. BPF returns only packets that pass the filter that the process supplies. This avoids copying unwanted packets from the operating system kernel to the process, greatly improving performance. The filter program is in the form of instructions for a virtual machine, which are interpreted, or compiled into machine code by a just-in-time (JIT) mechanism and executed, in the kernel.

Eclipse OpenJ9 is a high performance, scalable, Java virtual machine (JVM) implementation that is fully compliant with the Java Virtual Machine Specification.

Tracing just-in-time compilation is a technique used by virtual machines to optimize the execution of a program at runtime. This is done by recording a linear sequence of frequently executed operations, compiling them to native machine code and executing them. This is opposed to traditional just-in-time (JIT) compilers that work on a per-method basis.

Java bytecode is the instruction set of the Java virtual machine (JVM), crucial for executing programs written in the Java language and other JVM-compatible languages. Each bytecode operation in the JVM is represented by a single byte, hence the name "bytecode", making it a compact form of instruction. This intermediate form enables Java programs to be platform-independent, as they are compiled not to native machine code but to a universally executable format across different JVM implementations.

asm.js is a subset of JavaScript designed to allow computer software written in languages such as C to be run as web applications while maintaining performance characteristics considerably better than standard JavaScript, which is the typical language used for such applications.

Android Runtime (ART) is an application runtime environment used by the Android operating system. Replacing Dalvik, the process virtual machine originally used by Android, ART performs the translation of the application's bytecode into native instructions that are later executed by the device's runtime environment.

<span class="mw-page-title-main">Google JAX</span> Machine Learning framework designed for parallelization and autograd.

Google JAX is a machine learning framework for transforming numerical functions, to be used in Python. It is described as bringing together a modified version of autograd and TensorFlow's XLA. It is designed to follow the structure and workflow of NumPy as closely as possible and works with various existing frameworks such as TensorFlow and PyTorch. The primary functions of JAX are:

  1. grad: automatic differentiation
  2. jit: compilation
  3. vmap: auto-vectorization
  4. pmap: SPMD programming

References

  1. "LuaJIT". LuaJIT. Retrieved 25 February 2022.
  2. 1 2 "LuaJIT/COPYRIGHT at v2.1 · LuaJIT/LuaJIT". GitHub . 7 January 2022.
  3. "[ANN] Looking for new LuaJIT maintainers - luajit - FreeLists". www.freelists.org. Retrieved 2023-03-29.
  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. Deniau, Laurent. "Lua(Jit) for computing accelerator beam physics". CERN Document Server. CERN. Retrieved 25 February 2022.
  8. "OpenResty® - Official Site". openresty.org.
  9. "Lua - Neovim docs". neovim.io. Retrieved 2024-05-07.
  10. "Kong/kong". GitHub. Kong. 25 February 2022. Retrieved 25 February 2022.
  11. "Helping to make Luajit faster". blog.cloudflare.com. 19 October 2017. Retrieved 25 February 2022.
  12. "LuaJIT Performance".
  13. "Laurence Tratt: The Impact of Meta-Tracing on VM Design and Implementation". tratt.net. Retrieved 2 March 2022.
  14. 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.
  15. Pall, Mike. "Tuning numerical computations for LuaJIT (was Re: [ANN] Sci-1.0-beta1) - luajit - FreeLists". www.freelists.org.
  16. Rottenkolber, Max. "Later Binding: Just-in-Time Compilation of a Younger Dynamic Programming Language." ELS. 2020
  17. "Extensions". LuaJIT. Retrieved 25 February 2022.
  18. "BitOp Semantics". LuaJIT. Retrieved 25 February 2022.
  19. "Coco - True C Coroutines". LuaJIT. Retrieved 25 February 2022.
  20. "FFI Library". LuaJIT. Retrieved 25 February 2022.
  21. "Extensions". luajit.org. Retrieved 2022-08-25.
  22. "DynASM Features". DynASM. Retrieved 25 February 2022.