Effect of LUA Scripting
Moderator: Moderators
-
- Posts: 42
- Joined: 28 Dec 2008, 00:42
Effect of LUA Scripting
LUA scripts are a completely interpreted scripting language that can call bindings in C and vice versa through callin and callout functions (from what I've read) Just yesterday I start doing a bit of research on the LUA script language.
POINT: I started thinking about how slow LUA Scripts are and how they could effect FPS in a game. As a result, I was wondering if there was a more direct way of adding a client side mod to speed it up. Though for the most common of scripts, this isn't needed, but there are a few sketchy widgets out that don't exactly help FPS.
Or do I have the wrong idea?
POINT: I started thinking about how slow LUA Scripts are and how they could effect FPS in a game. As a result, I was wondering if there was a more direct way of adding a client side mod to speed it up. Though for the most common of scripts, this isn't needed, but there are a few sketchy widgets out that don't exactly help FPS.
Or do I have the wrong idea?
Re: Effect of LUA Scripting
The two main things that will drop performance are rendering and using a very bad algorithm. Rendering is very hard to optimize, while using a sane algorithm is usually pretty easy. Either way, the relative speed of lua vs. C doesn't come into play. If you do need to run heavy calculations, your first reaction should be to make sure it's really necessary, and then you can make a dll or so and load it from lua.
-
- Posts: 42
- Joined: 28 Dec 2008, 00:42
Re: Effect of LUA Scripting
Cool, thinks for the heads up. And I read about the name on the Lua website. Sorry :$
Re: Effect of LUA Scripting
The "Group AI" use .dll you can write in C++, and hopefully haven't yet been completly removed. They were supposed to do the same thing Lua widgets do nowaday, but never caught on.
Re: Effect of LUA Scripting
group AIs ARE already compleetly removed. they will not be available in the next release anymore. so you should not use them.
-
- Posts: 42
- Joined: 28 Dec 2008, 00:42
Re: Effect of LUA Scripting
I'm just curious as to why we are making everything in a high level script that is interpreted! It costs CPU and time in some cases. Plus it's like learning a bad version of Basic. Though I guess it's not always needed...
Last edited by computerquip on 27 Mar 2009, 00:21, edited 1 time in total.
Re: Effect of LUA Scripting
because it's easy to write and distribute and you don't have to use it if it's too slow or otherwise broken.
Re: Effect of LUA Scripting
Yes, you are optimising prematurely. There are many situations where Lua can be faster than C given the same amount of development time. In other words there are optimisations inherent to the way Lua performs hashing or memory management that are extremely efficient. If you tried to emulate these in C you would not have the benefit of the many years that went into Lua's development. If you spent the time optimising up to Lua's standards that would be time you could have spent optimising your actual bottlenecks (like network code or inefficient opengl).computerquip wrote:Or do I have the wrong idea?
The whole point of Lua and other interpreted languages is to let you develop your code much more quickly. Then, with the benefit of of actual working code, you can benchmark to locate your actual speed problems and move those functions, and only those functions, into C.
Finally, Lua is MUCH faster than other interpreted languages - it should not be painted with a broad (interpreted=slow) brush until you've tested it within the context it is being used. Keep in mind as well that interpreted or not it is loaded as bytecode (like java) so it does not suffer much after the lua file is first loaded.
The short answer is, if something needs to be fast in Spring it's probably already in the engine as a Lua wrapper around a C++ function or as C++ only code. This is why certain things like pathfinding have limited or no Lua interfaces. If you find something that requires C++ speed and isn't in the engine there's a reasonable chance that it could be a useful addition to the engine itself. If so then the Spring devs are always open to patches, if not then put it in a DLL and import the DLL directly via Lua's package system.
-
- Posts: 42
- Joined: 28 Dec 2008, 00:42
Re: Effect of LUA Scripting
In that sense, Java could also be faster than C++ or C. But clearly it is not. Is this a result of Java being poorly coded or a result of it being interpreted? If Lua is so well coded then why doesn't it get used more often?
The fact is that even with the great programming, it will still be more efficient in C and C++ for reasons quite clear through the ease of programming of Lua. Because they do not require a type, all variables in Lua I'm assuming allocate a large amount of space. This can clearly be avoided in C and C++. Also, Lua doesn't have the simple use of pointers and references which are available in the native code, C++. This is a MUCH more effecient way of passing variables to a function instead of copying temporary variables all over the place. And I'm sure there is much more that I'm missing.
POINT: Lua is in NO way efficient enough for large projects!
The fact is that even with the great programming, it will still be more efficient in C and C++ for reasons quite clear through the ease of programming of Lua. Because they do not require a type, all variables in Lua I'm assuming allocate a large amount of space. This can clearly be avoided in C and C++. Also, Lua doesn't have the simple use of pointers and references which are available in the native code, C++. This is a MUCH more effecient way of passing variables to a function instead of copying temporary variables all over the place. And I'm sure there is much more that I'm missing.
POINT: Lua is in NO way efficient enough for large projects!
Last edited by computerquip on 27 Mar 2009, 02:17, edited 2 times in total.
Re: Effect of LUA Scripting
I may be wrong, but I'm pretty sure that, rather than being interpreted, Java is actually compiled into .class files, then run inside a virtual machine.
PS: Thanks for listening. That's one less LUA in the world!

PS: Thanks for listening. That's one less LUA in the world!

Re: Effect of LUA Scripting
It is used as the scripting language for many games, including large-scale commercial ones. As for your original question, native code as a part of a mod is more or less infeasible, at least in the sense of maintaining spring's cross-platform compatibility.computerquip wrote:If Lua is so well coded then why doesn't it get used more often?
-
- Posts: 42
- Joined: 28 Dec 2008, 00:42
Re: Effect of LUA Scripting
I apologize for posting a premature post. Please read my post above.
Re: Effect of LUA Scripting
Does not work in Gadgets, does not work in Linux and will not work in Windows, afaik.SpliFF wrote:if not then put it in a DLL and import the DLL directly via Lua's package system.
Re: Effect of LUA Scripting
The interesting thing about optimization is that you can always, always make it faster. Using a language that's a factor slower doesn't matter nearly at all for most applications.computerquip wrote:POINT: Lua is in NO way efficient enough for large projects!
- Evil4Zerggin
- Posts: 557
- Joined: 16 May 2007, 06:34
Re: Effect of LUA Scripting
Semi-related question: Is there anything that is faster in COB than it is in Lua (excluding, of course, things that can only be done in one or the other)?
Re: Effect of LUA Scripting
This argument is as idiotic and wrong-end-of-the-sticky as those saying that the lobby server should not be written in Java/Python. 

Re: Effect of LUA Scripting
Doubtful. My highly inaccurate for loop test said "Lua for the love of god Lua"
Re: Effect of LUA Scripting
e4z: depends on the jit being active or not; actually i don't know if luajit is working. if it is, lua should be faster pretty much always, otherwise cob will be faster at the stuff cob does, which is moving ints around and nothing more. can't get faster than that without a jit, it simply makes the cpu do less for the same result.
Re: Effect of LUA Scripting
My empty for loop was 20x faster in lua (once I made it use numbers that fit into 24 bits so it wouldn't hang). I don't know why, but it was. I think I'll make a test of a few simple programs.