How to debug performance

This one’s really subtle, so thanks for sharing! It led to some good discussion / a good idea for a perf improvement for future versions of arcade.

I made a few small changes that bumped it up from about ~12fps to about about ~17fps on my meowbit (and ~25-30 on the second level):

The key part here is that this part:

has some side effects that may be surprising. images that are static (i.e. not editted at run time, only in the image editor itself) have some benefits for us – we can guarantee they’re the same as they started, and so we can use that in the physics. Once they’re changed at runtime – cloning in this case, but even just setting a single pixel – that is no longer true. At that point, we have no guarantees that the images haven’t been mutated beneath us - if we aren’t careful, you’ll have sprites passing through the tilemap because pixels were changed without updating the hitbox.

In this case, we’re being very careful, and updating the hitbox for every sprite every single frame that the image they are currently set to is one that is modified at runtime (and on some occasions, a few times in a single frame):

This makes us build a bounding box of the pixels in the sprite, so it’s a little expensive – not too bad usually, but really bad for fps when it’s done constantly.

We have an idea of how to fix this in the future (current plan in my head is something along the lines of an ‘editCount’ on the image itself that we increment on each edit to the image in the c++, that we can track on the hitbox and only update the hitbox when that does not match), but for now the easiest thing is to just make all the images you can in the image editor – all I did in this case was copy the original images and use the horizontal flip tool in the image editor.

and side note – if you need to edit the image at runtime for a game to work that is totally fine, especially if it’s only a handful of images! The bad case just comes up when it’s repeated across a ton of sprites that exist at once – so getting rid of runtime edits when possible is ideal. It’s also important on hardware because it saves memory space, as we only have to allocate space in memory for the image when it is modified at runtime.

5 Likes