Labs: Corona, Lua, and Scripting
The performance ‘ceiling’ of a scripting language needs to be high enough to allow for a game designer to express his or her creativity. The more a designer can do in their sandbox, the better the final game. Its important to find that balance, where the big and hard stuff exists in C, and the creativity and fun is expressed in script. Ansca Mobile is a prime example of a company who’s found that balance, and shown that you can do a LOT with a scripting language!
A bit of debate occurred over on the Garage Games forum regarding the unrealistic nature of my second part of the iTorque2D vs. Cocos2D performance tests. The gist is that I shouldn’t be doing what I’m doing with TorqueScript. I should be taking anything ‘related to performance’ and re-writing them in C. I disagreed in the forum:
I’m familiar with the concept that you should move your core loops out of TorqueScript, and have been doing exactly that in our game code. I expect that any performant process should happen in c, and with that in mind we have all kinds of special function such as getting an AABB of a set of sprites, special collision processing, box2d, etc, all in tight C loops.
But iterating over 100 items and doing some minor logic? That’s not a huge number. I think that should be feasible in a scripting language, without requiring a developer to retool a designer’s code to make it production ready.
Someone else said that I shouldn’t be doing this stuff on every frame in a production game in a scripting language. I don’t think this is unrealistic. But even internally there is debate about whether this is a good idea or not. The poster brought up Lua as an example of how slow something could run. Well, another great game engine, Corona, expects you to write in Lua. So I thought I’d whip out my Corona trial and write up some code.
To view this as a comparison between iTorque2D and Corona, I had to increase my number of iterations from 100 to 10,000 in order to get enough data to provide a useful idea of scope. Based on these numbers, Lua is approximately 50x faster than TorqueScript in simpler tests, and 16x faster in more complex tasks.
- Running a loop over 100 sprites that does similar logic as my iTorque2D test in Corona: 3ms.
- Empty for loop: 100,000 iterations: 11ms.
- Iterating over 10000 ‘tables’ and accessing a value and putting it into a local var: 5ms
- Iterating over 10000 ‘tables’ and doing a pong-style loop: 20ms
- Iterating over 10000 ‘tables’ and accessing two sub-table values, and putting those values into a local var: 70ms
I will agree with this guy’s summary from his Lua Performance post:
“I think we can conclude that Lua is pretty fast.”