Progressively slower frame rate on device during play when I stopped using graphics.sprite.removeAll

I'm wondering if anyone has experienced a progressive degradation of their game's framerate while attempting to deal with adding and removing animated sprites. I'm using SDK 2.5.0 and so far I've only been able to see this slowdown on the device (it's probably just too subtle to detect on the simulator).

Background: I'm making a platformer with a fixed camera. When the player leaves a screen, I load another one, first removing the previous screen's sprites and then adding in the new ones. Originally I did this by simply calling graphics.sprite.removeAll with each new screen. This worked fine, but on the device, load times became very long for some of the more complex screens. Some investigation revealed that adding the new sprites was causing most of the slowdown.

To address this, I stopped removing all the sprites and instead removed the ones specific to the screen (tiles, entities etc) while retaining the player's sprite and some commonly-reused other sprites. Most of these are using the AnimatedSprite library which seems pretty performant. This improved my transition times substantially; however, I began to notice that the frame rate would steadily degrade over a long play session. This effect can be seen even more quickly once I introduce complex animated entities, seen in the Mirror capture below:

In this video, the turret sprite is definitely causing the slowdown to accelerate. When I remove it from the scene, the same slowdown does eventually occur when switching between these screens, but it takes much longer.

Also note that the slowdown is specifically related to changing screens. I can stand on the screen with the turret without any more slowdown occurring, seemingly indefinitely.

I've added some logic to have a limited pool of entities which are only added to the display list once, and hidden until they're needed, but that doesn't seem to fix the problem. As far as I can tell, there are not multiple copies of the turret sprite being created. I'm not sure what's causing such a drag on the device's resources.

This is probably a pretty esoteric problem, but maybe someone has some insight or has dealt with similar performance issues?

It's difficult to say without seeing code but the most useful tools to figure this out are the Sampler window and the sample wrapper that you can use to add your own info into that window.

https://sdk.play.date/inside-playdate/#M-profiling

This is how I solved similar things in Daily Driver and Circular.

1 Like