how to make performDiscreteCollisionDetection() more fast?

Post Reply
kangd
Posts: 9
Joined: Tue Oct 24, 2017 11:51 am

how to make performDiscreteCollisionDetection() more fast?

Post by kangd »

Hi,

currently I am using Bullet physics for collision detection.

I created btCollisionWorld with one btStaticPlaneShape object and one btSphere object as follows,

Code: Select all

  collisionConfiguration_ = new btDefaultCollisionConfiguration();
  collisionDispatcher_ = new btCollisionDispatcher(collisionConfiguration_);
  overlappingPairCache_ = new btDbvtBroadphase();
  collisionWorld_ = new btCollisionWorld(collisionDispatcher_, overlappingPairCache_, collisionConfiguration_);

Code: Select all

  btCollisionShape* floorCollisionShape = new btStaticPlaneShape(btVector3(0, 0, 1), 0);
  btCollisionObject *floorCollisionObject = new btCollisionObject();
  floorCollisionObject->setCollisionShape(floorCollisionShape);

Code: Select all

  btSphereShape* sphereCollisionShape = new btSphereShape(radius);
  btCollisionObject* sphereCollisionObject = new btCollisionObject();
  sphereCollisionShape->setMargin(0.0);
  sphereCollisionObject->setCollisionShape(sphereCollisionShape);
As I added these object to btCollisionWorld by

Code: Select all

collisionWorld_->addCollisionObject(...)
and run performDiscreteCollisionDetection(),

I found the running time of performDiscreteCollisionDetection() is around 0.4 us for no collision situation and 0.8 us for collision situation.

(in CPU: Intel® Core™ i7-7700HQ CPU @ 2.80GHz × 8, GPU: Intel® Kabylake GT2 )

As I compare these with the benchmark result from http://www.bulletphysics.org/mediawiki- ... tFramework, my running time is significantly slow. (a benchmark result for non-moving 8000 box with btDbvt is 0.4 ms. I found running time is of the performDiscreteCollisionDetection(n) is almost O(n), thus my result for 8000 box would be apprx. 3 ms which is 10 times slower)

Is this usual? or Am I missing something here? Any suggestion to accelerate my collision checking would be appreciated.


--------
In summary,

1. btCollisionWorld with btDefaultCollisionConfiguration, btDbvtBroadphase, btCollisionDispatcher
2. two object (one is btSphereShape and another one is btStaticPlaneShape)
3. performDiscreteCollisionDetection()
4. run time of performDiscreteCollisionDetection() is

0.4 usec for no collision, 0.7 usec for collision. (in CPU: Intel® Core™ i7-7700HQ CPU @ 2.80GHz × 8, GPU: Intel® Kabylake GT2 )


Cheers!
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: how to make performDiscreteCollisionDetection() more fas

Post by drleviathan »

My first thought is: The real cost of performDiscreteCollisionDetection(n) is O(n) + O(1) and when n is very small the O(1) term may dominate. Your test has very small n therefore extrapolating to large n will not be accurate.

My second thought is: Why don't you run the 8k box test on your setup and actually measure Bullet's real costs for that case?

My third thought is: What version of Bullet are you using? Did you build it yourself? On what platform?

Finally: I don't know if your numbers are expected. I've never made such measurements and cannot corroborate the stats on that wiki page.
kangd
Posts: 9
Joined: Tue Oct 24, 2017 11:51 am

Re: how to make performDiscreteCollisionDetection() more fas

Post by kangd »

Thank you so much for your response.

1. I tested with 100 sphere + plane and run time of performDiscreteCollisionDetection(n) seems like linear as you mentioned (it was almost x100 of run time). So I don't think O(1) term is an issue here.

2. Honestly, I wanted to test 8k benchmark on my setup, but I couldn't find it's source code (or exec file). The link is not valid anymore. Do you know where can I get the source or exec file?

3. I am using bullet 2.87 (the latest one) at Linux 64bit.



and one more comment, since sphere + plane setup is very simple calculation, I thought I could get run time of 0.05 us order. (as the benchmark result says) Could you have any suggestion to make performDiscreteCollisionDetection() faster, or any other alternative ways to query the collision?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: how to make performDiscreteCollisionDetection() more fas

Post by drleviathan »

Looking at the code... I see that btCollisionWorld::performDiscreteCollisionDetection() calls btCollisionWorld::updateAabbs() which checks an optional optimization whereby it avoids updating the AABB of inactive objects. So in the case of 8k non-moving (and inactive!) objects there would be a measurable performance improvement when doing this in your configuration step:

Code: Select all

world->setForceUpdateAllAabbs(false);
There are some consequences of this config that affect "moving inactive objects around" but that is not really a problem for a benchmark. I should mention that I've chosen to use this optimization in one of my own projects. For performance, of course.

Perhaps try that config setting to see if you get timing improvements?

Meanwhile, according to the history of that wiki page... it was written back in 2008. The CDTestFramework is no longer part of the codebase but the git logs indicate that it was there in September 2012, so it was probably removed after that. It should be possible to checkout an older version of the codebase to recover it. You could then examine the code so see what exactly it was doing for its config. And you could perhaps port it to the modern codebase and try running it yourself.
Post Reply