Static fixtures 300,000+ performance issues

I don't know if I'm being unreasonable or not..but I was under the impression that static bodies were essentially free. I'm doing a tile based game and each tile was a b2Body.

I knew that wasn't a nice approach so after I got things working I optimized it to use only 1 body and n fixtures attached to said body, where n == number of tiles. I have 300k fixtures attached to said body. I changed it so it did this because I figured the performance problems were from it walking the body list, but that does not seem to be the case.

Right now I've got 2 bodies and 300,000 fixtures attached to one body (the other one is a player).

that one tile body is set to static..but it just brings my server's tickrate to its knees...

Memory isn't an issue it's just cpu usage..I can post code if you would like, just wanted to make sure (a) i'm not being unreasonable and (b) i'm not doing something stupid.

I'm going to eventually tie neighboring fixtures together, condensing them..but that's an optimization for later, not something to bring it out from the gutter.
Does the player need to interact with all of these 300,000 fixtures within the space of say, 10-20 seconds? If not I would suggest only loading those in a closer area around the player, and updating the world in chunks. If yes, maybe you could look into using spatial hashing instead of the dynamic tree that Box2D uses to narrow down which fixtures to test for collisions. Other improvements might be to use chain/edge shapes instead of tiles, assuming you have polygons now. Obviously removing redundant fixtures by condensing them would help too, but I think the answer to your overall question is yes, 300,000 is kinda unreasonable.
irresistible force wrote:
Does the player need to interact with all of these 300,000 fixtures within the space of say, 10-20 seconds? If not I would suggest only loading those in a closer area around the player, and updating the world in chunks. If yes, maybe you could look into using spatial hashing instead of the dynamic tree that Box2D uses to narrow down which fixtures to test for collisions. Other improvements might be to use chain/edge shapes instead of tiles, assuming you have polygons now. Obviously removing redundant fixtures by condensing them would help too, but I think the answer to your overall question is yes, 300,000 is kinda unreasonable.


Unfortunately, that is what I am doing, loading the area in chunks, but this number gets hit when you've got 5 players here 🙁
okay, repeat my last post but replace 300,000 with 60,000 😀

Original thread: https://box2d.org/forum/viewtopic.php?t=9276