Welcome to awesome bug tracking system.

FS#890 - Luajit support

Attached to Project: awesome
Opened by Aleksey Kunitskiy (marten) - Monday, 11 April 2011, 11:44 GMT
Last edited by Uli Schlachter (psychon) - Monday, 02 January 2012, 07:25 GMT
Task Type Evolution Request
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity Medium
Priority Normal
Reported Version git/3.4
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 5
Private No


It would be nice to have awesome working with luajit[1] instead of lua. It'll
gave a possibility to run more resource-hungry widgets that will eat less system resources.

Official website says luajit has compatible ABI with lua library but i've tried
to fix awesome 3.4.9 to link against luajit and there was a couple of runtime

This task depends upon

Closed by  Uli Schlachter (psychon)
Monday, 02 January 2012, 07:25 GMT
Reason for closing:  Fixed
Additional comments about closing:  commit 0181a64468b5766af252664254b597567434a19d
Author: Uli Schlachter <>
Date: Wed Oct 12 13:05:57 2011 +0200

Screen: Convert from lightuserdata to userdata

Setting a metatable on a lightuserdata sets the metatable for *all*
lightuserdata. Only tables and userdata have per-instance metatables.

This commit is an ugly hack to convert screen objects to real userdata.

Mailing list thread: w-managers.awesome.devel/6543

Signed-off-by: Uli Schlachter <>
Comment by Uli Schlachter (psychon) - Monday, 11 April 2011, 15:52 GMT
What kind of stuff are you doing in awesome? Oo

Also, can't you just move the slow stuff to an external process? Something that writes its results to /tmp/foo every few seconds.

Here's my try with luajit:

$ LD_PRELOAD=/tmp/usr/lib/ ./
/home/psychon/projects/awesome/build/lib/awful/tag.lua:480: calling 'tags' on bad self (screen expected, got userdata)
/etc/xdg/awesome/rc.lua:2: loop or previous error loading module 'awful'
E: awesome: main:546: couldn't find any rc file

awful.tag is only the 7th out of almost 20 awful modules, so there might be more trouble ahead.
Comment by Aleksey Kunitskiy (marten) - Monday, 11 April 2011, 16:22 GMT
> What kind of stuff are you doing in awesome? Oo
Consider using tons of widgets like net/cpu/temp/memory/disk/battery/clock
etc... Each of it consumes some resources which have impact i.e. on laptop
runtime and awesome responsiveness. With luajit I can switch refresh rate to
0.5sec for all widgets and I'll get better performance and less cpu-consuming
awesome (considering 2x-64x lua vs. luajit speedup And after all awesome should be really
awesome =)

> awful.tag is only the 7th out of almost 20 awful modules, so there might be more
> trouble ahead.
Luajit claimed to be ABI compatible with lua, therefore it may be not that much
to fix ;)

Comment by Uli Schlachter (psychon) - Monday, 11 April 2011, 16:39 GMT
But battery life is mostly impacted by number of wakeups. Once the CPU is running, it doesn't matter *that* much if it's running for a little longer.

For the luajit problem:
I guess the error says that it doesn't recognize that the userdata that was passed in really is a screen. So I guess something went wrong with setting the metatable or with the metatable registry, but I don't know anything more specific than that and I don't have the time to investigate.
Comment by Tai Chi Minh Ralph Eastwood (Raedwulf) - Wednesday, 07 September 2011, 08:53 GMT
This is a hack that actually allows luajit to work fine:

So far, I've not encountered any bugs... but I'm going to run it for a while longer than 30 seconds to find out!
Comment by Grygoriy Fuchedzhy (gry) - Wednesday, 07 September 2011, 12:44 GMT
I've started using it. Works fine so far. I'll report if everything is okay in a month. Thanks!
Comment by Uli Schlachter (psychon) - Wednesday, 07 September 2011, 13:37 GMT
Any idea why only that one luaL_checkudate() doesnt work and all the others are fine? That certainly seems weird.
Comment by Tai Chi Minh Ralph Eastwood (Raedwulf) - Wednesday, 07 September 2011, 14:35 GMT
It appears that screen.c doesn't use checkudata anywhere else.
In fact, there's only two occurrences of checkudata...

objects/client.c: cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, iidx, OOCAIRO_MT_NAME_SURFACE);
screen.c: screen_t *s = luaL_checkudata(L, 1, "screen");

It would be interesting to see if the objects/client.c one is broken by luajit too!
Ideally, if I can construct a small testcase, I can post this bug to Mike Pall.
Comment by Uli Schlachter (psychon) - Wednesday, 07 September 2011, 14:43 GMT
Oh, everything else in awesome uses luaA_checkudata() which does... something else. The lua bindings in awesome always contain surprises.

Since you found the OOCAIRO_MT_NAME_SURFACE: That one is registered in oocairo (oocairo.c / 826) via luaL_newmetatable(). screen is done via luaA_openlib() which uses... luaL_newmetatable(), too. :-(
Ok, I have no idea. Good luck with the small testcase. Please keep this bug updates with everything you figure out. Sadly, I don't think I'll have much time to help you, but feel free to ask anyway.
Comment by Grygoriy Fuchedzhy (gry) - Friday, 07 October 2011, 15:13 GMT
While using it for a month with a lot of widgets haven't discovered any issues at all.
Comment by Joško Nikolić (josko) - Sunday, 01 January 2012, 21:56 GMT
Using awesome v3.4-595-g47238fe (built on 6 Dec) and luajit2 (built on 6 Dec) with vicious widgets and works great so far.
Comment by dodo (dodo) - Sunday, 08 January 2012, 19:14 GMT
i'm just testing awesome with luajit and i must say, there is a noticeable performance increase.

@psychon any change this finds its way permanently into core? :D
Comment by Uli Schlachter (psychon) - Sunday, 08 January 2012, 21:18 GMT
Uhm, wtf? What exactly are you doing that is faster now? I have a hard time imagining that this actually has any noticable effect.

Also, what do you mean with "permanently into core"? It works, doesnt it? What's missing?
Comment by dodo (dodo) - Sunday, 08 January 2012, 21:44 GMT
i had to apply these changes:

hm .. it's probably faster because i use an high amount of widgets (all in pure lua) :P
Comment by Jörg Thalheim (Mic92) - Friday, 13 January 2012, 16:04 GMT
If the needed changes only consist of compile-time options, they could be integrate in the cmake file.
And everybody who wants to try luajit, could compile it itself.
Comment by Aleksey Kunitskiy (marten) - Tuesday, 06 May 2014, 09:55 GMT
LuaJit cmake compile time option
Comment by Uli Schlachter (psychon) - Tuesday, 06 May 2014, 21:59 GMT
From a quick look:

This basically copies CMake's FindLua52 module (even though it still claims to be Lua51 e.g. in the arguments to FIND_PACKAGE_HANDLE_STANDARD_ARGS), the module defines LUA51_FOUND which doesn't belong in a module called FindLuaJIT20 and meh, hardcoding version numbers? It's already bad enough that we have to hardcode lua's version number (although there is a bug somewhere that's supposed to make that go away).

Also I'm too lazy right now to check if the FILE() calls actually work, but I'd be worried....
And does luajit really require -lm on unix? How can that possible work with -Wl,--as-needed?

And finally, don't submit patches by hijacking old bug reports.
Comment by Aleksey Kunitskiy (marten) - Wednesday, 07 May 2014, 06:20 GMT
You're right, that was not ready not for submit, just a basic idea.
If there will be more clean patch I'll open a new bug report.