What are some tools to benchmark lua scripts?
Moderator: Moderators
What are some tools to benchmark lua scripts?
I would like to run some checks on my gadgets and widgets. How can I check their cost?
Re: What are some tools to benchmark lua scripts?
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.
The widget profiler you can find with forum search may still work for every mod on the other hand.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: What are some tools to benchmark lua scripts?
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.
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.
Re: What are some tools to benchmark lua scripts?
The 'idiots-guide to writing efficient lua' is here:
http://trac.caspring.org/wiki/LuaPerformance
http://trac.caspring.org/wiki/LuaPerformance
Re: What are some tools to benchmark lua scripts?
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.
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.
Re: What are some tools to benchmark lua scripts?
identifying bottlenecks is a different part of optimization
you can still apply the performance hacks for a potential several hundred percent improvement
you can still apply the performance hacks for a potential several hundred percent improvement
Re: What are some tools to benchmark lua scripts?
Some bottlenecks are unavoidable, the best you can do is spread the load out over multiple frames.
Re: What are some tools to benchmark lua scripts?
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.
Re: What are some tools to benchmark lua scripts?
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
Re: What are some tools to benchmark lua scripts?
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.
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.
Re: What are some tools to benchmark lua scripts?
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.
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.
Re: What are some tools to benchmark lua scripts?
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
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

Re: What are some tools to benchmark lua scripts?
Does it not use Script.SetWatchWeapon like the Explosion() callin does? I guess there are some non-weapon projectiles like flying unit pieces.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.
Re: What are some tools to benchmark lua scripts?
Hmm I don't know that, might be the case.
- TheFatController
- Balanced Annihilation Developer
- Posts: 1177
- Joined: 10 Dec 2006, 18:46
Re: What are some tools to benchmark lua scripts?
I wonder if LuaJIT would detect that most of these loops did nothing and execute them once or not at allFLOZi wrote:The 'idiots-guide to writing efficient lua' is here:
http://trac.caspring.org/wiki/LuaPerformance
Re: What are some tools to benchmark lua scripts?
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.Does it not use Script.SetWatchWeapon like the Explosion() callin does? I guess there are some non-weapon projectiles like flying unit pieces.