jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.42k stars 414 forks source link

Poor performance with high amount of static colliders #1081

Closed Armynator closed 4 months ago

Armynator commented 4 months ago

I've compared Jolt to PhysX 4, PhysX 5 and bepuphysics2 for large worlds today. The result: Jolt is unusable in big static worlds. From the project readme it looks like it's designed to load and unload only the nearby area. On a dedicated server this isn't really possible however.

What I'm doing:

While PhysX and bepuphysics2 handle this easily, Jolt completely dies with a high amount of static colliders in the simulation. After around 10k static colliders the tick times are completely unacceptable already (200ms+). PhysX and bepuphysics2 on the other hand can easily handle 2 million chunks/static colliders with less than 5ms per tick. (this is an extreme and unlikely test case, but puts the difference to Jolt clearly into perspective)

I've also tested it with regular box colliders instead of meshes, with the same result. After ~10-20k static colliders (with spacing between them) Jolt gets unusable, while PhysX and bepuphysicsv2 stay totally unimpressed far into the millions.

So... is this expected? or is there something special I have to do for this usecase to work?

jrouwe commented 4 months ago

I would say that a lot of static colliders should not be a problem. Horizon easily had 100K static colliders active at the same time and the update took a couple of ms. Have you perhaps misconfigured your object layer configuration so that you're mixing dynamic and static objects in the same broad phase tree? The majority of those static objects should be in a tree that changes very infrequently.