Significant slowdown after upgrading from 2.75 to 2.76

User avatar
cort
Posts: 6
Joined: Sun Mar 02, 2008 9:06 pm

Significant slowdown after upgrading from 2.75 to 2.76

Post by cort »

I've just upgraded from Bullet 2.75 to 2.76 (svn 2050), and I've noticed a significant decrease in my application's performance. I'm viewing a very simple test scene, a few hundred simple rigid bodies falling onto a ground plane and coming to rest. The relevant physics code is pretty much copied straight out of Bullet's AppBasicDemo. In debug builds, the once-per-frame call to m_dynamicsWorld->stepSimulation() after the scene reaches a mostly steady state went from ~12ms under Bullet 2.75 to ~38ms under Bullet 2.76. In release builds, the same call took ~6ms in 2.75 and ~11ms in 2.76.

I know that's not too much to go on, but are there any immediately obvious places I should look to figure out where the problem lies? If there's any more data I could provide to help track it down, let me know.

Thanks!
- cort
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Significant slowdown after upgrading from 2.75 to 2.76

Post by Erwin Coumans »

Strange, performance shouldn't drop when upgrading.

Can you provide a dump of 'CProfileManager::dumpAll' for both versions (after a stepSimulation that is slow)?

Also sharing a binary file.bullet would help, here is some description how to do that with Bullet 2.76:http://bulletphysics.org/mediawiki-1.5. ... ialization
Thanks for the feedback,
Erwin
User avatar
cort
Posts: 6
Joined: Sun Mar 02, 2008 9:06 pm

Re: Significant slowdown after upgrading from 2.75 to 2.76

Post by cort »

Here you go! Both samples were taken from debug builds, about 100 frames into the simulation -- not a 100% scientific comparison, but definitely representative of both cases. Let me know if you'd like a release-mode comparison as well.

I may be a layman, but it looks as though the trouble lies within dispatchAllCollisionPairs()...

Profile from 2.75 build:

Code: Select all

----------------------------------
Profiling: Root (total running time: 15.307 ms) ---
0 -- stepSimulation (99.95 %) :: 15.299 ms / frame (1 calls)
Unaccounted: (0.052 %) :: 0.008 ms
...----------------------------------
...Profiling: stepSimulation (total running time: 15.299 ms) ---
...0 -- synchronizeMotionStates (1.57 %) :: 0.240 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (98.31 %) :: 15.040 ms / frame (1 calls)
...Unaccounted: (0.124 %) :: 0.019 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 15.040 ms) ---
......0 -- updateActivationState (0.02 %) :: 0.003 ms / frame (1 calls)
......1 -- updateActions (0.01 %) :: 0.001 ms / frame (1 calls)
......2 -- integrateTransforms (1.21 %) :: 0.182 ms / frame (1 calls)
......3 -- solveConstraints (5.46 %) :: 0.821 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.08 %) :: 0.012 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (91.93 %) :: 13.827 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (1.20 %) :: 0.181 ms / frame (1 calls)
......Unaccounted: (0.086 %) :: 0.013 ms
.........----------------------------------
.........Profiling: solveConstraints (total running time: 0.821 ms) ---
.........0 -- processIslands (96.22 %) :: 0.790 ms / frame (1 calls)
.........1 -- islandUnionFindAndQuickSort (3.29 %) :: 0.027 ms / frame (1 calls)
.........Unaccounted: (0.487 %) :: 0.004 ms
............----------------------------------
............Profiling: processIslands (total running time: 0.790 ms) ---
............0 -- solveGroup (79.49 %) :: 0.628 ms / frame (95 calls)
............Unaccounted: (20.506 %) :: 0.162 ms
...............----------------------------------
...............Profiling: solveGroup (total running time: 0.628 ms) ---
...............0 -- solveGroupCacheFriendlyIterations (22.61 %) :: 0.142 ms / frame (95 calls)
...............1 -- solveGroupCacheFriendlySetup (18.95 %) :: 0.119 ms / frame (95 calls)
...............Unaccounted: (58.439 %) :: 0.367 ms
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 13.827 ms) ---
.........0 -- dispatchAllCollisionPairs (99.02 %) :: 13.691 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (0.01 %) :: 0.002 ms / frame (1 calls)
.........2 -- updateAabbs (0.93 %) :: 0.129 ms / frame (1 calls)
.........Unaccounted: (0.036 %) :: 0.005 ms
Profile from 2.76 build:

Code: Select all

----------------------------------
Profiling: Root (total running time: 34.141 ms) ---
0 -- stepSimulation (99.98 %) :: 34.133 ms / frame (1 calls)
Unaccounted: (0.023 %) :: 0.008 ms
...----------------------------------
...Profiling: stepSimulation (total running time: 34.133 ms) ---
...0 -- synchronizeMotionStates (0.51 %) :: 0.173 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (99.44 %) :: 33.943 ms / frame (1 calls)
...Unaccounted: (0.050 %) :: 0.017 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 33.943 ms) ---
......0 -- updateActivationState (0.01 %) :: 0.004 ms / frame (1 calls)
......1 -- updateActions (0.00 %) :: 0.001 ms / frame (1 calls)
......2 -- integrateTransforms (0.55 %) :: 0.185 ms / frame (1 calls)
......3 -- solveConstraints (0.48 %) :: 0.164 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.03 %) :: 0.009 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (98.39 %) :: 33.395 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.51 %) :: 0.173 ms / frame (1 calls)
......Unaccounted: (0.035 %) :: 0.012 ms
.........----------------------------------
.........Profiling: solveConstraints (total running time: 0.164 ms) ---
.........0 -- solveGroup (4.88 %) :: 0.008 ms / frame (1 calls)
.........1 -- processIslands (73.17 %) :: 0.120 ms / frame (1 calls)
.........2 -- islandUnionFindAndQuickSort (14.02 %) :: 0.023 ms / frame (1 calls)
.........Unaccounted: (7.927 %) :: 0.013 ms
............----------------------------------
............Profiling: solveGroup (total running time: 0.008 ms) ---
............0 -- solveGroupCacheFriendlyIterations (25.00 %) :: 0.002 ms / frame (1 calls)
............1 -- solveGroupCacheFriendlySetup (25.00 %) :: 0.002 ms / frame (1 calls)
............Unaccounted: (50.000 %) :: 0.004 ms
............----------------------------------
............Profiling: processIslands (total running time: 0.120 ms) ---
............0 -- solveGroup (25.00 %) :: 0.030 ms / frame (2 calls)
............Unaccounted: (75.000 %) :: 0.090 ms
...............----------------------------------
...............Profiling: solveGroup (total running time: 0.030 ms) ---
...............0 -- solveGroupCacheFriendlyIterations (13.33 %) :: 0.004 ms / frame (2 calls)
...............1 -- solveGroupCacheFriendlySetup (33.33 %) :: 0.010 ms / frame (2 calls)
...............Unaccounted: (53.333 %) :: 0.016 ms
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 33.395 ms) ---
.........0 -- dispatchAllCollisionPairs (99.53 %) :: 33.238 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (0.01 %) :: 0.005 ms / frame (1 calls)
.........2 -- updateAabbs (0.44 %) :: 0.148 ms / frame (1 calls)
.........Unaccounted: (0.012 %) :: 0.004 ms
You do not have the required permissions to view the files attached to this post.
User avatar
cort
Posts: 6
Joined: Sun Mar 02, 2008 9:06 pm

Re: Significant slowdown after upgrading from 2.75 to 2.76

Post by cort »

Hi Erwin -- have you had a chance to look at these captures yet?

thanks,
- cort
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Significant slowdown after upgrading from 2.75 to 2.76

Post by Erwin Coumans »

It seems the narrowphase collision detection has issues with your data set indeed. From the .bullet files it seems most objects are btCompoundShape.
When loading and simulating the file they all drop down without collisions.

Could it be there are some static collision shapes missing in the dump? (not all Bullet shapes are supported in the serialization yet)
Should there be some static collision shapes (btBvbTriangleMeshShape)?

Thanks a lot,
Erwin
compounds.png
You do not have the required permissions to view the files attached to this post.
User avatar
cort
Posts: 6
Joined: Sun Mar 02, 2008 9:06 pm

Re: Significant slowdown after upgrading from 2.75 to 2.76

Post by cort »

The only static collision shape is the ground plane; the falling shapes should hit it eventually and settle. Here's the relevant setup code, for whatever that's worth:

Code: Select all

btRigidBody *Physics::AddRigidBody(float mass, btCollisionShape* shape)
{
        //rigidbody is dynamic if and only if mass is non zero, otherwise static
        bool isDynamic = (mass != 0.f);

        btVector3 localInertia(0,0,0);
        if (isDynamic)
                shape->calculateLocalInertia(mass,localInertia);

        // Users are responsible for attaching motion state to objects that need it
        btDefaultMotionState* myMotionState = NULL;
        btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
        // TODO: expose restitution and friction to caller!
        rbInfo.m_friction = 10.0f;
        rbInfo.m_restitution = 0.20f;
        btRigidBody* body = new btRigidBody(rbInfo);
        body->setCenterOfMassTransform(btTransform::getIdentity());

        m_dynamicsWorld->addRigidBody(body);

        return body;
}

...

float groundHalfLength = 200.0f;
float groundMass = 0.0f;
btCollisionShape* groundShape = new btStaticPlaneShape( btVector3(0, 0, 1.0f), 0);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(groundHalfLength,groundHalfLength,0.0f));
btRigidBody *groundPlaneBody = g_pPhysics->AddRigidBody(groundMass,groundShape);
groundPlaneBody->setWorldTransform(groundTransform);
The slowdown occurs immediately at startup, though, before anything actually collides with anything else. Very odd.
- cort