How to Optimize Performance?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

How to Optimize Performance?

Post by MrJohnny »

I have an actor that spawns a bunch of other actors after a time. The problem however, is that there's a huge dip in performance once all the actors spawn. Everything works as it should, but the sudden performance dip is jarring and doesn't look pleasant at all. I understand that spawning a bunch of actors at one time tends to be taxing, but is there some way to mitigate this? Thanks!

By the way, giving the spawned actors the "NOINTERACTION" flag is not doable since I need them to be affected by gravity.
Spoiler:
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: How to Optimize Performance?

Post by Matt »

Just brainstorming a few thoughts...

If some of these are really small and you can get away with using dots you could try using A_SpawnParticle (and specify downward acceleration for the gravity effect).

Sometimes it helps to spawn the actors in smaller groups over the course of a few ticks - no one's going to be able to see through all those sprite effects from the first batch to notice the "missing" second/third/fourth/fifth.

You might want to experiment with using a custom function instead of calling a zillion frames of A_SpawnItemEx. (I'm not sure if this actually improves performance any)

Do you really need that many debris actors when maybe fewer larger ones will do?

Sometimes, if you know what you're doing (and perhaps more importantly what the actor need not be doing, a Tick() override with some seriously simplified interactions might help. Here's HD's debris actor, for example, which basically just moves, bounces and updates frames, responds to a few behaviour-modifying flags and does nothing else.

It might even be possible to spawn actors over a period, tuck them away in like (32000,32000,32000) or wherever, then *move* them and set their state+velocity+sprite as needed, thus avoiding the need for initializing new actors.
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: How to Optimize Performance?

Post by MrJohnny »

Matt wrote:Do you really need that many debris actors when maybe fewer larger ones will do?
I've thought about it, but I don't believe there's any way to accomplish this without making things look awkward. The reason there's so many actors is because I want to give the illusion of the sprite crumbling to pieces. For this to work, positioning/angles is important; I essentially made actors for each individual "piece" of the sprite and spawned them all at one time to make it look cool. 8-)

I'm not that experienced with zscript, so my options are somewhat limited. Despite this, I will attempt to try some of your suggestions. I appreciate the reply!
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: How to Optimize Performance?

Post by Matt »

Looking at the code again I see you're spawning 116 actors in more or less the same place all in one tic.

That's a lot for just one destruction animation though GZDoom runs fine on my computer with hundreds and hundreds of actors on the map (if not together on the screen) at once. The main chokepoint really does seem to be initializing those actors.

If you did them in batches of 10 with a 1-tic delay in between each batch (meaning all pieces would be spawned in less time than it takes for an imp to finish its walk cycle once) I suspect things could improve significantly. (And if the spawning looks too obvious there's always adding smoke and flames at the beginning.)
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: How to Optimize Performance?

Post by MrJohnny »

Hmmm... batches of 10 didn't make much of a difference, but a 1-tic delay between each A_SpawnItemEx helped a bunch. It doesn't quite give the desired effect this way though. Maybe I can just spawn the actors at the start of the level, and then modify their velocities/gravity when I want them to "crumble." Will report back on my endeavors. Thanks again Matt!
MrJohnny
Posts: 212
Joined: Fri Aug 05, 2016 8:41 am

Re: How to Optimize Performance?

Post by MrJohnny »

Happy to say that pre-initializing the actors worked wonders. Seems like most of my issues have been solved. :D

Return to “Scripting”