• LuaJIT for Garry's Mod
    101 replies, posted
  • Avatar of Johncw87
  • [b]ATTENTION![/b] I've recently updated and re-purposed this module. It used to implement LuaJIT 1.1.7 (or 2.0.0) into garrysmod years ago, but garrysmod has since implemented LuaJIT 2.0.0. The module now implements LuaJIT 2.0.3 into garrysmod, but it won't be long before it becomes obsolete again. [url]http://dl.dropbox.com/u/20789739/gmod_luajit.rar[/url] The installation instructions haven't changed, so read below. Old post preserved below: [quote]For those who don't know, LuaJIT is a library that runs Lua code much faster than the standard interpreter. This module detours every single Lua API function that exists in lua_shared.dll with ones from LuaJIT 1.1.7 to give Garry's Mod a performance boost. I modified LuaJIT 1.1.7 with the same syntax changes that gmod Lua has, even the bitwise operators (I had to write [i]assembly[/i] to make [i]that[/i] work). I also [b]included the coroutine fix[/b] I posted before in the "What are you working on?" thread. [url]http://dl.dropbox.com/u/20789739/gmod_luajit.rar[/url] There is also a WIP LuaJIT 2.0.0 module in there with the name 'gmod_luajit2' [b]Installation:[/b] For dedicated servers: Place the module somewhere in the addons folder and create a *.vdf for it. This sample *.vdf is placed directly in the addons folder and assumes the module is also in the addons folder: [code] "Plugin" { "file" "../garrysmod/addons/gmod_luajit" } [/code] For Garry's Mod clients: Place the module in the 'garrysmod/garrysmod/bin folder, and prefix the name with 'game_shader_generic_'. Example name: [code] game_shader_generic_gmod_luajit.dll [/code] [b]Usage:[/b] Nothing special is required to use LuaJIT once it is installed, however, you may be interested in the [url=http://luajit.org/ext_jit.html]extra library added by LuaJIT[/url]. [b]Didn't someone already make a LuaJIT module?[/b] Yes, but mine doesn't require any special code to use. [b]How compatible is this with other modules?[/b] If the other module detours/calls lua API functions from lua_shared.dll, then it will conflict. However, you [i]could[/i] change the conflicting module yourself so that it detours/calls the functions from this module instead of lua_shared.dll, and it should work fine. The module exports the LuaJIT API functions to make this easier. If you have problems with the module, let me know. Just don't bug me if your scripts error because 'arg' was nil. The implicit use of 'arg' in vararg functions is deprecated and not supported in LuaJIT. [/quote]
  • Avatar of BomBom
  • I can't seem to get this plugin to load :/ Always get this error when the server starts. [code] Unable to load plugin "../garrysmod/addons/gmod_luajit" [/code]
  • Avatar of gamerpaddy
  • [CODE] Garry's Mod server.dll Build #130 - Linux [Dec 1 2011 11:14:41] Unable to load plugin "../garrysmod/addons/gmod_luajit" [/CODE] Linux... :(
  • Avatar of Robber
  • Didn't garry already add LuaJIT to GMod and removed it again after it started crashing GMod?
  • Avatar of BomBom
  • [QUOTE=gamerpaddy;34924914][CODE] Garry's Mod server.dll Build #130 - Linux [Dec 1 2011 11:14:41] Unable to load plugin "../garrysmod/addons/gmod_luajit" [/CODE] Linux... :([/QUOTE] A Linux version would be nice but it doesn't even work on my windows servers.
  • Avatar of SiPlus
  • "file" "../garrysmod/addons/gmod_luajit" Replace "garrysmod" with "garrysmodbeta". Or try just typing "file" "addons/gmod_luajit" instead.
  • I'd love to see some performance comparisons, I remember the old one but didn't use it enough to test.
  • Avatar of OldFusion
  • [QUOTE=Robber;34924998]Didn't garry already add LuaJIT to GMod and removed it again after it started crashing GMod?[/QUOTE] Yea something to do with try/catch statements in combination with LuaJIT would cause it to break on valve's DirectX 7.0 Implantation, and also a lack of var_arg support. Worked fine server side however. [url]http://lua-users.org/lists/lua-l/2010-10/msg00514.html[/url]
  • Avatar of Johncw87
  • [QUOTE=BomBom;34924809]I can't seem to get this plugin to load :/ Always get this error when the server starts. [code] Unable to load plugin "../garrysmod/addons/gmod_luajit" [/code][/QUOTE] You might be missing a dependency. Make sure you have the latest Visual C++ 2005 Redistributable installed. [editline]29th February 2012[/editline] [QUOTE=BlackAwps;34927113]Would love to see a linux build.[/QUOTE] I can't even begin to think about a linux build unless I can find the linux server binaries, which seem to be missing from the dedicated server install. I vaguely remember the binaries being posted on the forums, but I can't seem to find it. I would also need a cross-platform detours library (or at least one that works on linux)
  • [QUOTE=Jcw87;34927731]I can't even begin to think about a linux build unless I can find the linux server binaries, which seem to be missing from the dedicated server install. I vaguely remember the binaries being posted on the forums, but I can't seem to find it. I would also need a cross-platform detours library (or at least one that works on linux)[/QUOTE] The best I can do is upload the linux binaries for you. [url]http://dl.dropbox.com/u/38214687/lin_mac_bins.rar[/url]
  • Avatar of Nexus435
  • [QUOTE=OldFusion;34927528]Yea something to do with try/catch statements in combination with LuaJIT would cause it to break on valve's DirectX 7.0 Implantation, and also a lack of var_arg support. Worked fine server side however. [url]http://lua-users.org/lists/lua-l/2010-10/msg00514.html[/url][/QUOTE] Who is still using DX7?
  • Avatar of Johncw87
  • [QUOTE=garry;34924629]Nice work - any performance comparisons?[/QUOTE] I haven't run any, but the official site has a comparison chart between standard Lua, the stable version of LuaJIT, and the development version of LuaJIT. [url]http://luajit.org/performance_x86.html[/url] [QUOTE=Megalan;34927819]1.1.7? Why not 2.0? It's a lot faster. Gonna try and update it.[/QUOTE] Development versions tend to be less stable, and gmod crashes enough already. I didn't want to add to that. I could stick the new version in if you really want it, though. [QUOTE=BlackAwps;34929511]The best I can do is upload the linux binaries for you. [url]http://dl.dropbox.com/u/38214687/lin_mac_bins.rar[/url][/QUOTE] Thanks for that. It appears that the linux binaries don't have symbols like I've heard they do, so it will probably be a while before I decide to start disassembling it to look for function signatures.
  • [QUOTE=Jcw87;34937275]Thanks for that. It appears that the linux binaries don't have symbols like I've heard they do, so it will probably be a while before I decide to start disassembling it to look for function signatures.[/QUOTE] That's why I included the mac binaries. I'm pretty sure it will have the symbols you would need for linux.
  • [QUOTE=Jcw87;34937275] Development versions tend to be less stable[/QUOTE] I have several applications developed using latest beta of luajit running 24/7 for at least several months. None of them crashed yet.
  • Avatar of CapsAdmin
  • yeah i've never had any issues with the 2.x version of luajit in my projects either
  • Avatar of pennerlord
  • Made a shitty test with this script: [lua] local t = SysTime() for i=1, 2000 do print(i) end print(SysTime() - t) [/lua] I have run it 5 times (each with and without luajit). My results: Without luajit: [code]0.02301025390625 0.0230712890625 0.02398681640625 0.0235595703125 0.02166748046875[/code] With luajit: [code]0.021163940429688 0.020851135253906 0.022552490234375 0.021713256835938 0.021484375[/code] So I guess it's really faster, isn't it?
  • Avatar of SB2DevTeam
  • [QUOTE=pennerlord;34943155]Made a shitty test with this script: [lua] local t = SysTime() for i=1, 2000 do print(i) end print(SysTime() - t) [/lua] I have run it 5 times (each with and without luajit). My results: Without luajit: [code]0.02301025390625 0.0230712890625 0.02398681640625 0.0235595703125 0.02166748046875[/code] With luajit: [code]0.021163940429688 0.020851135253906 0.022552490234375 0.021713256835938 0.021484375[/code] So I guess it's really faster, isn't it?[/QUOTE] Could you test it using stuff like entities? so engine functions get called. Should be more accurate then just a simple thing like that :p
  • Avatar of pennerlord
  • [QUOTE=SB2DevTeam;34943177]Could you test it using stuff like entities? so engine functions get called. Should be more accurate then just a simple thing like that :p[/QUOTE] Next test: [lua] local t = SysTime() local ply = player.GetByID(1) for i=1, 100 do local ent = ents.Create("prop_physics") ent:SetModel("models/Combine_Helicopter/helicopter_bomb01.mdl") ent:SetPos(ply:GetPos() + Vector(0,0,200)) ent:Spawn() print(i) end print(SysTime() - t) [/lua] Results: Without luajit: [code]0.030975341796875 0.016754150390625 0.016815185546875 0.017242431640625 0.019500732421875[/code] With luajit: [code]0.03314208984375 0.0166015625 0.016845703125 0.0164794921875 0.0166015625[/code] Luajit is still faster.
  • Avatar of garry
  • The thing you guys are missing is it's not going to make calling a function (like print) faster, because its just calling a function - hardly anything is happening Lua side. Try doing calculations in Lua side. Multiplying 50,000 numbers, merging huge tables etc etc. It's not going to make any function calls faster unless they dip back into Lua.
  • Avatar of Wizard of Ass
  • [QUOTE=garry;34943483]The thing you guys are missing is it's not going to make calling a function (like print) faster, because its just calling a function - hardly anything is happening Lua side. Try doing calculations in Lua side. Multiplying 50,000 numbers, merging huge tables etc etc. It's not going to make any function calls faster unless they dip back into Lua.[/QUOTE] Even if its not making the C-bindings faster, its still a good improvement. So if even a third-party dev with no actual sourcecode can implement that without making the game unstable, why not give it another chance?
  • Avatar of OldFusion
  • [QUOTE=pennerlord;34943408]Next test: [lua] local t = SysTime() local ply = player.GetByID(1) for i=1, 100 do local ent = ents.Create("prop_physics") ent:SetModel("models/Combine_Helicopter/helicopter_bomb01.mdl") ent:SetPos(ply:GetPos() + Vector(0,0,200)) ent:Spawn() print(i) end print(SysTime() - t) [/lua] Results: Without luajit: [code]0.030975341796875 0.016754150390625 0.016815185546875 0.017242431640625 0.019500732421875[/code] With luajit: [code]0.03314208984375 0.0166015625 0.016845703125 0.0164794921875 0.0166015625[/code] Luajit is still faster.[/QUOTE] require("jit.opt").start() ?? [editline]1st March 2012[/editline] [QUOTE=garry;34943483]The thing you guys are missing is it's not going to make calling a function (like print) faster, because its just calling a function - hardly anything is happening Lua side. Try doing calculations in Lua side. Multiplying 50,000 numbers, merging huge tables etc etc. It's not going to make any function calls faster unless they dip back into Lua.[/QUOTE] There is still plenty of lua code getting executed. And the performance difference with 2.0 is quite a lot [img]http://cold.netburst.co.uk/file/Screenshot-2012-03-01_18.02.45.png[/img] In an avg gamemode you can find plenty of nested loops and hooks that get called a few times every frame.
  • Avatar of Johncw87
  • [QUOTE=OldFusion;34943827]require("jit.opt").start() ??[/QUOTE] That probably won't work. Garry's Mod is still using all of the same libraries and functions, and its require() and module loaders don't know about any embedded LuaJIT libraries. The only reason the 'jit' library is there at all is because I detoured luaL_loadlibs to load it. [QUOTE=Megalan;34941164]I have several applications developed using latest beta of luajit running 24/7 for at least several months. None of them crashed yet.[/QUOTE] Ok, I'm going to start working on sticking LuaJIT 2 in there.
  • Avatar of garry
  • [QUOTE=OldFusion;34943827]require("jit.opt").start() ?? [editline]1st March 2012[/editline] There is still plenty of lua code getting executed. And the performance difference with 2.0 is quite a lot [img]http://cold.netburst.co.uk/file/Screenshot-2012-03-01_18.02.45.png[/img] In an avg gamemode you can find plenty of nested loops and hooks that get called a few times every frame.[/QUOTE] I'm aware of those. I'm talking about people document speed increases in THIS module. Maybe timedemo the difference between two demos to show how drastic the difference is to make me want to implement it into GMod for real.
  • Avatar of Zeh Matt
  • I have to admit this is brilliant, it pretty much does what I was working on lately, but you were faster. I will try this out once I got more time