Page 1 of 1

How to Optimize Performance?

Posted: Fri May 06, 2022 6:23 pm
by Pompous Seed
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:

Re: How to Optimize Performance?

Posted: Tue May 10, 2022 7:10 pm
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.

Re: How to Optimize Performance?

Posted: Thu May 12, 2022 1:48 pm
by Pompous Seed
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!

Re: How to Optimize Performance?

Posted: Thu May 12, 2022 11:14 pm
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.)

Re: How to Optimize Performance?

Posted: Fri May 13, 2022 4:48 am
by Pompous Seed
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!

Re: How to Optimize Performance?

Posted: Fri May 13, 2022 6:52 am
by Pompous Seed
Happy to say that pre-initializing the actors worked wonders. Seems like most of my issues have been solved. :D