TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
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
@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
up vote 25 down vote accepted

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)

share|improve this answer

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.

share|improve this answer
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
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
Be aware that luajit has ffi: http://luajit.org/ext_ffi.html which can increase performance drastically if used properly. The links are still down though after several months. So is there no luaJITLatex? – Archival Feb 22 '13 at 12:30
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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