Rotating Bodies Cause Massive Performance Drop

I first noticed when I tried adding three large bodies with revolute joints and activated the motors. With motors activated, I get major framerate issues for ~10seconds before the framerate returns to normal.

Suspecting maybe an issue with the revolute joint, I changed the bodies from Dynamic to Kinematic and set the angular velocity directly to rotate them. This resulted in the exact same slow down.

Putting it into a profiler revealed 20% of the frame time being spent on b2DynamicTree::InsertLeaf. Calls to this function drop off dramatically after about 10 seconds the framerate returns to normal.

Any ideas what's going on here?
Are you creating a large number of fixtures?
The bodies have 67 fixtures each and are 25 meters in diameter.

Maybe the sheer size is causing the problem?
You may have an older version of the code that had some inefficiencies in the dynamic tree. You might want to try the latest code in SVN.
Are you using SetTransform() many times in a row?

I think I once had this issue with Farseer Physics Engine and it was caused by ContactManager->FindNewContacts() being called on each call to SetTransform().
Yes, I am using SetTransform() !!

I didn't have time to debug this further, so I just simplified the geometry and brought the fixture count down enough to get a good framerate.

I will upgrade Box2d in the near future and post whether or not it makes a difference. Others beware that just rotating large numbers of fixtures may bring Box2d to it's knees.
I am experiencing the exact same problem as described by Kiaran.

I have a large kinematic body, with a about 20 fixtures on it, with its rotation velocity set.

I get a massive performance spike in the physics processing, which dissapears as soon as I stop the objects rotating.

I believe it is the b2DynamicTree "reordering itself" as the fixtures change position.
However it is such a huge performance hit that I need to fix this, any help would be appreciated ^_^

kiaran wrote:
I first noticed when I tried adding three large bodies with revolute joints and activated the motors. With motors activated, I get major framerate issues for ~10seconds before the framerate returns to normal.

Suspecting maybe an issue with the revolute joint, I changed the bodies from Dynamic to Kinematic and set the angular velocity directly to rotate them. This resulted in the exact same slow down.

Putting it into a profiler revealed 20% of the frame time being spent on b2DynamicTree::InsertLeaf. Calls to this function drop off dramatically after about 10 seconds the framerate returns to normal.

Any ideas what's going on here?
Do you have a recent version from SVN? The dynamic tree is much faster now. If that doesn't help, try disabling continuous collision.
Yups, its the latest version from subversion.
Disabling continuous physics made no noticable difference to my timings.

However after a bit of playing around I found that changing b2_aabbExtension (from b2Settings.h) from 0.1f to 1.0f gave a massive speed increase.

I presume changing that value may give me issues in other situations, but for now it seems to run better.

Oh, great physics engine by the way ^_^

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