What is so special about LuaJIT?

The first thing that stands out about LuaJIT is that it is an extremely fast high-level language.With factor 1.3 (rarely worse) behind C, it is effectively faster than most compiler languages, equal to the best (after C). In other words, you get the full power of a dynamic high-spirited language for a negligible price.

The second thing that stands out about LuajIT is that it is very small.With a memory overhead of 800 kb, it is not relevant for most projects. The best high-end languages do this in 10 times size, but often rather 100 times the size. Size in this case means that large parts of the language fit into the processor cache and thus do not put so much strain on the Von Neumann bottleneck and also contribute significantly to the speed.

What do we get for this cheap price?We get a very simple language that is easy to learn and maintain, with 22 keywords it is one of the leanest high languages after the esoteric language Brainfuck (8). However, it does not buy this small vocabulary to learn with inemanence or lack of flexibility. In fact, it contains all the means for all the paradigms of known programming, and through openness it even allows for more new ones that have not yet been invented. More on that later.

It comes without a dogma imposed on the programmer, a certain form that must be preserved and, unlike in today’s authoritarian languages, leaves all freedoms to him.This means starting with the procedural, one can opt for real functional programming, not only as with a Lambda calculus as with Python, instead with the full spectrum of this programming type, object-oriented programming one does not achieve classes, but by programming metafunctions on tables.

This sounds unfamiliar, but is brilliant at second glance.Because the data of a class is literally held in a table, it is perfectly sorted for the processor in memory and can therefore be processed quickly. The meta-functions are simple and universal and implement all the things that are artificially applied to the syntax in enforced object-oriented languages with “class” and a dozen additional keywords. For Lua, however, the idea of data encapsulation flows directly into the data itself.

Binding functions to data, restricting access, all this can be determined to the finest, by the open design not only access restrictions to inherited classes, but to certain users from the operating system, the complexity are no limits set except for one’s own imagination and needs.The concept thus goes much further than any other high language.

But it is unusual and takes a few minutes for the idea to fully unfold.Most people who scream for OOP are surprised that there is no “class” and “private” and all the keywords in this direction.

They are not necessary.Lua transcended them.

But LuaJIT is not an OOP language.It is a paradigmless language that is above all pragmatic and does not see paradigms as tools for describing and solving certain problems.

LuaJIT adheres completely to the 5.1 standard of the language, but implements all features of 5.2 that do not break 5.1, which is almost everything, according to experience.So we are in a 5.2 Lua. The 3rd Editon of the Lua book is the best reference. This includes the implementation of a “goto” as the most important extension over 5.1 and thus classic state machines can be programmed, which is only possible in other languages by recursive replacement constructions. However, lua 5.3 extensions do not exist. Unfortunately, these extensions make an effective JIT compiler impossible, which is why Mike Pall, the programmer of LuaJIT, strongly criticized these extensions when they were introduced, but his objections were brushed aside. As a result, 5.3 is virtually unused and LuaJIT is more or less the de facto standard of the language that virtually all libraries adhere to.

By the way, the Goto also makes the translation of other, older languages much easier and practically possible without having to completely change the basic structure of the old programs.

However, the implementation of a goto in a dynamic, structured modern language such as Lua is subject to certain limits, as in C.However, wild jumping around is not possible and probably undesirable.

If the state machine is not enough, you have access to coroutines, not just the little, backward brother, the generator used, for example, in Python and most other languages.Coroutines are not yet a real multitasking, but their own states of the Lua stack, to which one can return. This of course allows generators, say a loop with continuous Fibonacci numbers or similar, but also multi-level state jumping, as is required in the programming of AI and represents a grandiose extension of the state machine.

Read more here: Lua Coroutines Versus Python Generators

Again, the sleek and elegant implementation comes at such a low cost that unlike Python, where it takes an extremely long time, this elegant type of solution can be used without hesitation in many places.

It is not a theoretical solution but a practical one.With which Lua once again shows his pragmatism. What is the point of a solution that is theoretically present but which ultimately slows down the program by a factor of 100 to the point of unusability?

If that’s not enough, you’ve got real multitasking via the Posix library.Unlike in Python, there are actually multiple processes running in parallel and there is no global interpreter lock, which only allows a process to run at the moment, again the negative Python example.

LuaJIT also implements a very wide-ranging FFI extension that allows direct access to C libraries and even kernel functions.Except for LuaJIT, no high-speech is capable of booting a Linux kernel without outside help. The concept is very broad.

And it’s also the way you can implement other data types to run perfectly on the architecture.These include complex numbers, unions, structures, bit fields and everything that is possible in C. This often means a sharp reduction in storage requirements and a sharp acceleration compared to the more indirect pure high-level language access.

In addition, this method allows you to leave the 2 GB of dynamic memory, which was otherwise limited mainly by keeping the garbage collector efficiently.Lua can use it to manage any amount of memory, but keeps the garbage collector clear and fast at 2 GB.

This dual distribution of storage management alone is a huge performance advantage.

When it comes to extending LuaJIT, integrating C libraries, compared to other languages like Java or Python, is easy and fast.LuaJIT not only allows the called full access to the Lua Stack, which allows a call by reference beyond call by value, but allows the same of course if it is used as an embedded script to the caller. In addition, LuaJIT allows the libraries to implement their own data structures.

This means that the language remains transparent in its entire structure to the outside world, where other languages must always copy access back and forth via the call-by-value function calls and the return-by-value value through the function call bottleneck.A pretty unique feature in high-end language.

This has invaluable practical benefits.

LuaJIT is widely used in the industry.This starts with a full-fledged LUa-written IDE, Zerobrane, goes beyond the Mako/Barracuda servers commonly used in China and Asia because of their extreme performance, which replace languages such as PHP with Lua and outperform traditional servers like Apache even if you use the unfair comparison of Apache static websites, Barracuda dynamic.

You have the exact opposite of the Webvalium Ruby-on-Rails or Django under Python.

LuaJIT finds extensive use due to its advantages in the gaming industry, Love2D, Minetest, Minecraft, Lua Game Programing, Category:Lua-scripted video games and many more.The advantages of the language speak for themselves, here is also the very well controllable garbage collector, which can practically exclude dropouts by cleaning up if handled properly (most other dynamic high-level languages have no such mechanisms).

In games, you can’t afford to delay without damaging the product.Products such as CryEngine also speak for the language in their choice.

In the AI LuaJIT is used in Torch, the direct programming of the GPU runs through the OpenCL library, the performance of this library exceeds everything else one is accustomed to from high languages.

Here is another example: Hanno Behrens’s answer to Can you show me some Lua code?

The use of OpenCL can provide an acceleration of factor 100 to pure LuaJIT – comes to the graphics card and processor – and, as shown in the example, represent factor 42000 to Python.In this example, I actually took the best (running) implementation from Python’s Mandelbrot. There was no better one. Of course, this is a bit unfair, but that’s part of it: if you look for things like that, you find solutions in Lua, but in Python a lot of the solutions aren’t working and that’s a huge problem of progressive high-speech. A problem of all high-level languages, in fact, but significantly less by his more conservative approach to LuaJIT.

The digital forgetting of Lua is much less, but as with all high languages, it is slightly higher than with C. Libraries can fail if there are too many dependencies in the system.That’s why I didn’t take too much reference to system libraries into the comparison here.

The LuaPosix library provides access to all Posix functions.The versions included in the Debian repositories are all running and reach from Debian to the repository from (K)Ubuntu to Raspbian. If one becomes too progressive, however, this can lead to difficulties. I mention this because, when libraries are used, it almost always occurs at some point. I deleted all my Python libraries from the plate just because of such difficulties in the construction and arc, because Python has completely disassembled and gone up in smoke in its entirety. Such effects are extremely annoying and destroy hours of careful furnishing work.

With LuaJIT, these effects are very less.But that is a fundamental problem. Which is why dependencies should be better from C-library to C-library, not from high-end languages to high-language library experience. These are, of course, purely practical things, but they take an extremely long time and are much more pleasant on the side of Lua.

I recently stopped my experiments with Django not because of the miserable performance, but because of such inadequacies, the dissolution of which has led to days of fruitless work.

this problem is so bad with Python that you install multiple Python environments, with libraries that do not torpedo each other in the dependencies and the memory consumption decreases not only on the disk but also in the main memory Javaesque dimensions, which is why I strongly advise against using Python.

LuaJIT is a very pleasant alternative that solves these problems to my satisfaction, but not to the full satisfaction.But this is in the nature of the matter and is not lua’s fault, but is a problem of every HLL and the great dynamics in the codebase.

However, we must not go unmentioned.I just cursed about an extremely progressive version of Luaposix, which has pretty much dismantled the entire infrastructure through poor dependencies. Well. Thirty minutes of trouble and eliminating three progressive packages is a bit different than a full three weeks of trouble with Python and an OpenCL that I never got to run again after a system update.

And anyone who works with Python will be able to sing a song of.


Don’t ask how many hours I’ve sunk into this problem, while parts of it work, parts don’t. So very primitive OpenCL examples run under Python. The system is installed correctly. It’s actually because of this dilletantic handling of dependencies in Python, Ruby and all the other unprofessional shabby languages we’re currently being swept up with. Less is sometimes more.

LuaJIT, on the other hand, has been running flawlessly for years.Not a minute of outage. There is no such unprofessional annoyance here. And for me, that’s relevant, but some developers may see it differently.

Just to what the alternative looks like.When you have a bigger project going on, which is perhaps not just a homework assignment and that you still like to be running in two years, something like that becomes relevant. The other high-level languages are leading by a bad example, while Lua is not doing it perfectly, but really very good in comparison. And that is an extremely important factor for me. I don’t play with the stuff, I try to work with it.

So much for system stability, LuaJIT is not perfect, but I certify a good or even a 2+, which is excellent for a high language.I have nothing better. If you want to get into the one-zone, however, only C helps. My 1985 programs are still running…

Let’s get back to Lua in applications.LuaLaTeX, NeoViM, Nmap, Ethereal and many other programs diligently use Lua’s scripting capability by integrating it into their applications. This is not possible with other languages. Just can’t do it because you can’t access the stack of these languages from the outside.

LuaJIT is extremely flexible and, in terms of this, simply plays in a completely different league.Of course you can start Python scripts from C, like Perl or others, but they are not integrated, but they are started, do something, then come back. There is no interaction.

The original use of Lua 1.0 as a configuration language from the 90s has a valuable heritage here, which has a complete unique selling point in design and cannot be achieved with any high-level language.The others cannot. Completely impossible. And with Lua (JIT), this simply allows things to open completely new gates.

I’m still waiting for a Lua programmable spreadsheet.

The library support under Lua goes far.With Luaposix, complete system support, with ljsyscall complete kernel functions, gmp access to overlong numbers, lgsl supports far-reaching scientific functions, OpenCL GPU progrmament, Qt5 is supported as well as Gtk, wx widgets or SDL, Audio and midi capabilities, practically in real time and not only as a midi file, but with direct Alsa access, graphics via imlib2 or others, web access via socket or curl, mathematics via a maxima interface, BC, template programming, XML and JSON, RDF, semantic networks, GA genetic programming, OpenCV and other computer vision projects, Telegram connection, cryptography, Gnuplot, ncurses, IRC bots, HTML parsing, language parsing is extremely easy, PDF, Excel, Doc formats, Create LaTeX and dot vector graphics, Ansicolors, bit operations, debuggers, various SQL APIs, of course also the popular extremely fast SQLite3 Engine, memory map support by the kernel for extreme amounts of data in a system-managed virtual memory of any size, to just one to scratch a bit on the surface and what you, see MMap just don’t get on any high language. Impossible.

For the Raspberry Pi there is complete support of the system by RPi Lua, as well as conversions of LuajIT to Termux on any Android with extensive implementation of the Android API and the available sensors in the access.

Did I mention that you can create apps directly and interactively with Lua on Android, which then run much faster and smaller than the Java alternative?

So the things you could list here definitely go beyond a person’s lifetime.Should be enough.

Oh and you can of course precompose Lua and use it as binary blobs, also decentralized, also these blobs can be encrypted and digitally signed.Just on the sidelines. Try this in Python or Ruby. And with binfmt on Linux, these binaries can be run directly just like ELF files as executable with all the consequences.

Oh, I see. And LuaJIT is a German product.

Michael “Mike” Pall from Munich is the developer. It drives the most massive web servers in China and Asia. But the poet is not valid in his own country. Mike Pall has developed a groundbreaking JIT compiler “dynasm” for LuaJIT, which is now used by more and more languages. The thing is the epitome of German value work and, in my opinion, what comes closest to ingenious code. I haven’t seen anything in my life that was comparable.

I hope I could help.

Leave a Reply