What are some tools to benchmark lua scripts?

What are some tools to benchmark lua scripts?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

What are some tools to benchmark lua scripts?

Post by smoth »

I would like to run some checks on my gadgets and widgets. How can I check their cost?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: What are some tools to benchmark lua scripts?

Post by zwzsg »

There is, or was, a gadget profiler in CA. Once I tried to port it to KP, but I failed because CA handler was too different from default handler (for instance it wouldn't call GameStart). I suppose with a little work, CA handler with profiler could be merged with a more standard gadget handler. Or take the principle of CA's profiler and reimplement it in your own handler.

The widget profiler you can find with forum search may still work for every mod on the other hand.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: What are some tools to benchmark lua scripts?

Post by jK »

CA has a gadget profiler (synced and unsynced) & a LuaUI profiler.

The usage of the LuaUI profiler is easy.
And the gadget profiler works via "/luarules profile" & "/luarules uprofile".

PS: the widgetprofiler by Meltrax (the one linked by vbs) just covers a few callins, while the CA one covers all.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: What are some tools to benchmark lua scripts?

Post by FLOZi »

The 'idiots-guide to writing efficient lua' is here:
http://trac.caspring.org/wiki/LuaPerformance
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: What are some tools to benchmark lua scripts?

Post by zwzsg »

Optimising is not about applying magic recipes. It's about identifying the bottlenecks.

And once you find it, rethinking your algorithm will give you better performance gain than those small tricks anyway.
Last edited by zwzsg on 29 Sep 2010, 20:01, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: What are some tools to benchmark lua scripts?

Post by aegis »

identifying bottlenecks is a different part of optimization
you can still apply the performance hacks for a potential several hundred percent improvement
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: What are some tools to benchmark lua scripts?

Post by FLOZi »

Some bottlenecks are unavoidable, the best you can do is spread the load out over multiple frames.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: What are some tools to benchmark lua scripts?

Post by zwzsg »

aegis: Not really, because if you miss the bottleneck, you can optimising the rest all you want, it won't change a thing, since by definition it's the bottleneck that slows you down.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: What are some tools to benchmark lua scripts?

Post by FLOZi »

It'd be useful to also have a list of Call-in's which are particularly performance heavy.
[19:17:14] <[S44]FLOZi> hmmm, could rewrite the ammo gadget to use ProjectileCreated callin
[19:18:13] <[LCC]jK> bad idea
[19:18:26] <[LCC]jK> that's a very very performance critical callin
[19:18:35] <[LCC]jK> once you use it it hurts your fps
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: What are some tools to benchmark lua scripts?

Post by Tobi »

That's simple.

If it's called often, it's performance heavy.

ProjectileCreated is called for every single projectile that is created. So that could be many, many times in a single frame.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: What are some tools to benchmark lua scripts?

Post by aegis »

zwzsg, you can optimize some operations to get a decent performance boost. I have no idea why you would suggest AGAINST this.

you want drawing code executed every frame to be as fast as possible.


if you optimize the algorithms used in your bottlenecks and get a 2x speedup, that's great.
you should STILL optimize oft-used badly-performing calls (which can in fact be inside your bottlenecks!) if you can get another 2x.

following the lua performance guide offers an easy performance improvement. there's no feasible reason why anyone shouldn't apply it.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: What are some tools to benchmark lua scripts?

Post by Tobi »

If you have a single bottleneck that takes 90% of your CPU, and you waste all your time optimizing and tweaking the other 10% CPU usage, then no matter how good you are you are not going to make it more than 10% faster.

However, if you leave all your other code alone and just optimize the bottleneck a little, say 25%, then you already optimized the whole thing 22.5%!

Of course I am not arguing against using a speedier way to code something in the first place, but only as long as it does not reduce readability. As soon as you have a tradeoff between speed and readability, always choose readability, until you have measured that that particular code is a bottleneck.

I think that is also the point zwzsg is making :-)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: What are some tools to benchmark lua scripts?

Post by FLOZi »

Tobi wrote:That's simple.

If it's called often, it's performance heavy.

ProjectileCreated is called for every single projectile that is created. So that could be many, many times in a single frame.
Does it not use Script.SetWatchWeapon like the Explosion() callin does? I guess there are some non-weapon projectiles like flying unit pieces.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: What are some tools to benchmark lua scripts?

Post by Tobi »

Hmm I don't know that, might be the case.
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: What are some tools to benchmark lua scripts?

Post by TheFatController »

FLOZi wrote:The 'idiots-guide to writing efficient lua' is here:
http://trac.caspring.org/wiki/LuaPerformance
I wonder if LuaJIT would detect that most of these loops did nothing and execute them once or not at all
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: What are some tools to benchmark lua scripts?

Post by Argh »

Does it not use Script.SetWatchWeapon like the Explosion() callin does? I guess there are some non-weapon projectiles like flying unit pieces.
No, it doesn't. It's called every time a Projectile, including Pieces, is created. My experience is that so long as you're not doing major stuff there, it's fine to use. If you need to do major logic, use if-->then to filter out most things, ofc.
Post Reply

Return to “Lua Scripts”