Labs: Corona, Lua, and Scripting

April 12, 2011 by
Categories: Labs

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.

Surely enough, within about 5 minutes, I found the fishies demo, which has, almost verbatim, my exact pong loop. And it was in Lua! Time for some more testing.

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

You can find my lua file for Corona here.

I will agree with this guy’s summary from his Lua Performance post:

“I think we can conclude that Lua is pretty fast.”

3 Response(s) to Labs: Corona, Lua, and Scripting

  1. carlos icaza says:

    Nice !! Thank you.

    And here is something for you, part of our next release we will be doing a lot of performance tuning. Stay tuned :-)

    Carlos Icaza - co-founder Ansca, makers of Corona SDK.

  2. Hey thanks for linking to my blog entry!

    Yeah, Lua’s a really fast language; it still boggles my mind how anything uncompiled can run that fast (then have a go with LuaJIT… from what I hear that blows the socks off almost everything around).

    I personally use Lua in the LOVE engine (http://love2d.org), and it works like a charm. In that engine, it’s even been used to do live 3D simulations.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>