Is it possible to change the Lua engine in LuaTeX to LuaJIT?

Will it be as simple as replacing the Lua5.1 source code in the LuaTeX tarball with the LuaJIT source, or does it require (drastic) changes to the build system, or is it entirely not possible?

  • 2
    What would the advantage be over the current situation? – Joseph Wright Sep 20 '11 at 16:41
  • It is "claimed" to be faster. But I doubt if that performance boost will benefit LuaTeX much. On my MacBook pro the bottleneck of performance is loading fonts. But I believe that is actually related to the hard disk and memory since the loading time is almost proportional to the size of the fonts cache file. For example ArnoPro-Regular has an unbelievable 53MB cache file and cost in multi-GB memory after loading the standard two weights two shapes. This leads it to be extremely slow to load, while LMRoman will take little time to be noticed. – Yan Zhou Sep 20 '11 at 16:54
  • @YanZhou: That would depend on whether the function is implemented in Lua. In the case of loading otf fonts, AFAIK, the metric-extracting part done by fontforge libraries. I'm not sure about the loading-of-the-cached-metrics part, though. If that part is indeed implemented in Lua, then theoretically we should see both a speed increase and a memory usage decrease if LuaJIT is embedded instead of Lua5.1. – Jonathan Yip Sep 20 '11 at 17:11
  • 6
    I have TeX runs that last several minutes (up to an hour) and a few percent gain would be nice. – topskip Sep 20 '11 at 17:43
  • 2
    @YanZhou: That may be true for LuaLaTeX; ConTeXt MkIV makes heavy use of Lua so it might gain quite some speed. – Martin Schröder Sep 20 '11 at 19:32

I did an attempt a while ago with LuaJIT 1, and it did not seem to be that hard. A few small build tweaks would be needed, but nothing major.

The main reason why there is no LuaJIT in LuaTeX currently is that we have a few patches to Lua now that are not in LuaJIT (and are hard to add) like an extended coroutine subsystem. In lua5.2, our patches to the Lua core will become obsolete, so once we switch to that Lua version, LuaJIT becomes interesting again and I will certainly try to have LuaJIT support by default on the supported platforms. That should be before LuaTeX 1.0, but not in next few months.

But, don't expect much of it. Even in ConTeXt, most Lua processing is iterating over C data structures using our embedded Lua support libraries. JITting the little bit of Lua code that wraps that together will not help a lot, a few percent at best is my current guess (which is also why incorporating LuaJIT is low priority)


Since 2012-12-25 LuaJitTeX is available. It is LuaTeX with LuaJit based on Lua 5.1.

Two modes are available by default:

  • jit turned off, the default mode (only use the faster virtual machine)
  • jit turned on (in most cases not faster, even slower)

In ConTeXt standalone LuaJitTeX is included by default, which means using MkIV with LuaJitTeX is as easy as providing the --jit argument:

context --jit   somefile.tex  # or
context --jiton somefile.tex

For plainTeX simply use luajittex as compiler:

luajittex         --fmt=luajittex-plain.fmt somefile.tex  # or
luajittex --jiton --fmt=luajittex-plain.fmt somefile.tex

Building the format for plainJitTeX is no different than building the format for LuaTeX.

Just to provide an impression of the speed difference I did a quick non-scientific test on a simple document. Here are the results for a ConTeXt document with the three possible options:

Engine                      Compile time
------                      ------------
LuaTeX                      3.6s
LuaJitTeX (jit turned off)  2.9s
LuaJitTeX (jit turned on)   3.0s

Edit: There seems to be some confusion about how to obtain LuajitTeX. The project is hosted on foundry.supelec.fr - LuajitTeX. Recently they restructured their servers and relocated their content. Unfortunately the URLs changed and the old ones are not valid any longer. The sources can be obtained with SVN using

svn checkout --username anonsvn https://foundry.supelec.fr/svn/luajittex/trunk

The binaries can be found on the ConTeXt garden.

  • Where is LuaJitTex available? The link on the luatex homepage points to foundry.supelec.fr/gf/project/luajittex but this seems not to work anymore (404). – Alexander Feb 12 '13 at 11:28
  • Have you tried this timing with immensely large documents? – zeroth Feb 13 '13 at 10:27
  • 1
    No and it might not be of practical use to me. For large documents the complexity tends to increase paired with extensively using external programs during the run, but my documents rarely comprise more than a few hundred pages. It might not be too hard to create an example where either LuaTeX or Jit is faster but that result might be of limited value in practice. – Marco Feb 13 '13 at 10:41
  • 1
    @Archival The URL changed to LuajitTeX project page. I don't use LaTeX, but isn't it as simple as building the format and call luajittex --fmt=luajitlatex.fmt file.tex? If the format builds with luatex it should build with luajittex as well. – Marco Feb 22 '13 at 12:40
  • 1
    LuajitTeX seems to be part of TeX Live nowadays. – Raphael Aug 3 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.