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!)

How to Optimize Performance?

Postby Pompous Seed » Fri May 06, 2022 6:23 pm

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:
Pompous Seed
 
Joined: 05 Aug 2016

Re: How to Optimize Performance?

Postby Matt » Tue May 10, 2022 7:10 pm

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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: How to Optimize Performance?

Postby Pompous Seed » Thu May 12, 2022 1:48 pm

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!
Pompous Seed
 
Joined: 05 Aug 2016

Re: How to Optimize Performance?

Postby Matt » Thu May 12, 2022 11:14 pm

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.)
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: How to Optimize Performance?

Postby Pompous Seed » Fri May 13, 2022 4:48 am

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!
Pompous Seed
 
Joined: 05 Aug 2016

Re: How to Optimize Performance?

Postby Pompous Seed » Fri May 13, 2022 6:52 am

Happy to say that pre-initializing the actors worked wonders. Seems like most of my issues have been solved. :D
Pompous Seed
 
Joined: 05 Aug 2016


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests