Physics performance with many static bodies

Hello,

There is a performance issue when there are lots of physics bodies within a scene.

We can see in the inspector that a lot of time is spent in physics
image
But investigating further with devtools, I found out that most time is spent in HavokPlugin.sync() syncing back transforms from havok to the transform nodes, which is useless for static objects.

I implemented a workaround by adding a field to the body and overriding the sync() function

   hk.sync = function sync(body) {
        if (!body['doNotSync']) //set to true for high number of static bodies (eg walls)
            this.syncTransform(body, body.transformNode);
    }

(uncomment the lines at the end in the playground)

This brings back performance to normal levels

Iā€™m not sure how to move forward from here as I feel the plugin should not even need to sync back static bodies.
As there is no direct field for determining if a body is static, maintaining a proper list of static bodies would apparently need changes in PhysicsEngine, PhysicsBody and PhysicsPlugin.

2 Likes

Please open a github issue and assign it to me

Maintaining a list of bodies is for another PR, post 7.0 release.

5 Likes