Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
LuaJIT, is it worth it? — Gideros Forum

LuaJIT, is it worth it?

totebototebo Member
edited November 2014 in General questions
Hi guys,

Have you used LuaJit with Gideros and, if so, was the effort worth the performance increase in your case? I'd love to hear details about what kind of game you used it in, and exactly how it improved the performance.

http://giderosmobile.com/labs/luajit

Cheers,

Niclas

Likes: keszegh

My Gideros games: www.totebo.com
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • yes, no real effort required.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • i tried now to add luajit to my android project and it crashes. i disabled json as maybe they don't work together, but still i get white screen for a short time and immediate crash. any ideas what may cause this? does luajit work for you in android? (in the windows player it works fine for me)
  • my project is an android 5.0 project, if that matters (i think not).
  • Hey @sinistersoft, do you have an example of when LuaJIT has made a difference, in your experience? I'm trying to figure out in what scenario it would be most useful.

    I'm not going in head first because adding something magical like LuaJIT adds another question mark if when troubleshooting issues.
    My Gideros games: www.totebo.com
  • @totebo I think it's worth a try since it's really easy to switch it on and off. The "biggest" job is compiling a jit giderosandroidplayer for live testing, but I found it better to compile a test apk embedding jit libs to check its impact. :)

    There is only one requirement in coding I am aware of (you don't need to change it back , works in plain lua too) it's stated somewhere in this forum: if I recall it correctly it was something about function arguments like in
    function myfunc(arg)
    local arg = arg --you need to localize arg
     
    end
    Or something about

    function myfunc (...) usage - which I've never used personally because I didn't understood how to use it.. but is there in some lua lib that you may load ;)

    I'm sorry I can't check this right now without laptop nor wifi: search the forum for luajit and my notes (if I am right it was in a post from gregbug about tnt particle system) :)

    At this time in my game luajit it's not so worth (longer loading time, everything is a bit smoother, but on a single multiple pathfinding action there is a loong delay - I use jumper, but I suppose it's my fault since I use jumper in other actions and I don't have such delays. Plus, I'd like to support also older devices, every delay on these is doubled and there was no appreciable improvement overall).
    I've not given it up though, it does seem to increase performance on newer devices, not tested thoroughly yet. maybe in a near future I'll think about it again. :)

    @keszegh I can use json along with luajit and it's not crashing (android 4.4) I believe the "damage" is somewhere else in what you do with loaded data (or some "coding requirement" - see above)

    Hope this helps :)

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • @pie, thanks for your comments.
    well, if localization is necessary then that might be an issue for me too, i have plenty of functions without localizing the arguments. on the other hand jit version of windows player seems to be working fine with the same project.
  • Not exactly a localization, but lua automatically creates local variable arg holding table of all passed paraeters, then in luajit it does not, and you have to do something as:
    function test(...)
        --if function relies on arg variable, it won't exist here and you need to create it yourself
        local arg = {...}
    end

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • i see, i don't use this arg variable, so this cannot be my problem.

    is luajit working with android fine for everybody?
  • @keszegh you might not use it, but some libraries do, I have to rewrite couple of libs I created myself, as well as TNT libs to work with LuaJIT ;)
  • well, i see no appearance of 'arg' in any of the lua files i use (scenemanager, gtween, aceslide). do you have any common used library that you remember that might have this issue?
  • @keszegh try searching for (...) in all files/subdirectories with zerobrane, worked for me. :)

    I don't remember editing any file on your list for this issue, I used them all.

    If I recall correctly I had issues (easily solved) with the following libs and luajit:

    progressbar by @ar2rsawseen
    An outdated release of tnt particle system (latest already fixed)

    And, to use Tnt animator by @gregBUG with luajit you need its source file
  • @pie, @ar2rsawseen, thanks for the tips, mobdebug was the only thing that had "..." in it, i deleted it from my project but still when i copy over the luajit lib to plain lua lib, the game starts with a short time of white screen and then quits.
  • @keszegh if your code was exported lua precompiled, it can't be picked up by luajit.

    Installation mobiles

    Prerequisites

    To make mobile project work with LuaJIT you need to make some changes to Gideros Installation and reexport the project's assets again

    Windows installation

    • Inside Gideros installation folder, go to Tools folder and rename luac.exe to luac2.exe

    Mac OSX installation

    • Inside Gideros installation folder, right click on Gideros Studio and select Show Package Contents
    • Navigate to Contents/Tools and rename luac to luac2

    Android

    Copy libs folder from luajit folder into your exported project overriding existing liblua.so files

    IOS

    Copy liblua.a from luajit folder into your xCode's project folder overriding existing liblua.a

  • @ar2rsawseen, thanks for finally guessing what went stupid. now it works
    of course I read only the 'android' part and did not realize that the 'windows installation' part also has to be done for exporting to android properly.

    now that it works this way, I realize that it's a slight drawback with luajit that the lua files are completely exposed (encrypting is also not possible of them while using luajit). it's a bit more surprising for me that also the asset files cannot be encrypted - if i encrypt, then again it is not working. so everything is exposed.

    this may be enough for me to stay with plain lua as the performance gain might not be needed for me.

    @ar2rsawseen, @pie, thanks for your help
  • @keszegh the CAN be encrypted, they can't be precompiled, but you can still encrypt them ;)
  • @ar2rsawseen, both code and assets can be encrypted? that's great
    (for me it did not work, but it's hard to check when am i running what in eclipse, so i will try more then, perhaps i messed up something else)
  • @totebo When the code starts (with LuaJIT) there is a slight delay over a normal Lua program - this must be the compile stage - on most phones this is not noticable though.

    Other than that I'd say everything is faster - no complaints here.

    On a side note, the encryption with Gideros needs to be revisited as it's pretty easy to auto hack it out.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Thanks @sinistersoft.

    Likes: SinisterSoft

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • EricCarrEricCarr Member
    edited November 2014
    I agree, right now it is trivial to decrypt gideros lua files. I'm planning on updating the encryption part so the decryption key isn't stored in plaintext at the same relative location in every app, and builds unique encryption/decryption code that is different for every installation of gideros.

    Of course - I don't know how the framework stores lua code in memory. If you load an apk in an emulator and take a memory dump - how easy is it to access the original code even if it was encrypted?

    Access to source code may not be that important to some, except for retrieval of private keys used for encryption/public api access, etc.

    If you use luaJit, then today I can take your apk and recreate your exact project with original source lua+all assets. If you don't, it's more time consuming because I have lua byte code to deal with, some of which cannot be automatically decompiled.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • Compliled script byte by luajit will not work on 64 bit architecture.
  • @alexzheng It's compiled on the machine (JIT) otherwise it's still interpreted.

    @EricCarr Lua files have a header, so do other picture files - using this it's possible to figure out the XOR as it's too short before it repeats (it's about the same size as the Lua header that never changes!).
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • john26john26 Maintainer
    Just to give my experience, I did not notice any difference in speed running with Lua JIT versus the normal runtime. I was running a simple platform game which is probably not very Lua intensive anyway (see links). My impression is that Lua is already pretty fast and modern hardware is fast, so unless you are inverting matrices or something, you may not notice much difference.
  • Thanks all for your responses. :)

    Niclas
    My Gideros games: www.totebo.com
  • @sinistersoft the xor key is stored directly after a hard coded (never changes) series of bytes, so it can just be read to decrypt all files without needing to bother with brute force. I was wondering if lua keeps the lua byte code as-is in memory so getting by any encryption is as simple as taking a memory dump of an emulator.
  • hmm... yes - that would also work.

    One thing is for sure - the existing method needs to be changed.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.