Could Someone Give me Advice for Optimizing Performance in Heaps for Complex 2D Games?

Hello there,

I am working on a complex 2D game using Heaps; and I have reached a point where performance optimization is becoming a critical factor. The game involves a lot of dynamic elements; such as particle effects; AI-driven characters; and real time physics. While Heaps has been fantastic in handling these so far, I have noticed some performance dips; especially when there are many entities on the screen at once.

What’s the best way to manage rendering in Heaps when dealing with a large number of sprites and effects? Are there specific techniques or features within Heaps that can help reduce the rendering load?

I am concerned about memory usage as the game scales. How can I effectively manage memory in Heaps to prevent leaks or excessive usage? Are there particular data structures or practices within Heaps that are more memory-efficient?

I am using Heaps built in physics, but as the complexity of interactions increases, so does the computational cost. Are there ways to optimize physics calculations or any third-party libraries that integrate well with Heaps for this purpose?

Also, I have gone through this post; https://community.heaps.io/t/should-i-use-heaps-or-not-yet-beginner-blue-prism/ which definitely helped me out a lot.

Thank you in advance for your help and assistance.

Independently of the engine, my first suggestion would be to employ some space partitioning to avoid computing entities that are not visible. You won’t need to render them and maybe you do not even need to simulate their physics if their state when not in view is not relevant to the gameplay.

So it really is the rendering then that would need an efficiency boost?

Or does the issue also come into play when the entities are active, but not currently on the screen?

– If not so, that would probably make things like efficiency for memory management, AI and real time physics and entity interaction complexity neglectable for this particular problem.
(Btw solutions here were ECS and multithreading, smarter code (like what tanis mentions or e.g. from this book)…)

We have some people also on discord that are more familiar with how Heaps rendering works.