Hello together!
I am currently experimenting with ways to improve the ArcadePhysics performance of my game, because that is the main bottleneck.
For this, I set up a new repo to collect some best practices.
My first experiment is in using Object Pools:
I create 200 circle-formed ArcadeSprites, add them to one group, then disable their bodies, then add collision for the group with itself.
The use case would be for example just collision between units and walls.
You can “see” it live here: https://luccahellriegel.github.io/Phaser3-Best-Practices/prod/game.html
The code can be found here in the function oneGroup here:
https://github.com/LuccaHellriegel/Phaser3-Best-Practices/blob/master/src/physics-perf.ts
The sprites are created here:
https://github.com/LuccaHellriegel/Phaser3-Best-Practices/blob/master/src/util.ts
(These 20 lines is all that is happening)
The CPU Usage jumps to 40-60% from just doing the above, when I just was expecting an increase in Heap Size because there aren’t any collisions happening. There are also some peaks that go up to 80%. They can be reduced a little by removing the collision, the rest of the performance does not improve, which leads me to believe that disabled objects are CPU intensive anyways.
For reference an empty phaser game is at 5-10% CPU Usage.
My current question is, is using an ArcadePhysics ObjectPool a known Anti-Pattern?
Or phrased differently: why does it cost so many additional CPU cycles to have disabled circle-formed sprites?
While preparing this post, I also found out that you can cut the 40-60% by 20+% by having the disabled sprites not be circle shaped. (So, commenting out sprite.setCircle(40). Increasing the size of the sprite with sprite.setSize(40,40) does not reduce the performance). So it really is something about circles
that is tripping up the physics engine, even if the body is disabled.
All the best,
Lucca
