[solved] scale world 100x -> performance increase 3x

Post Reply
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

[solved] scale world 100x -> performance increase 3x

Post by hyyou »

It is surprising that just scale every thing make so much difference in performance. :shock:

First Experiment
I created a scene with 1,000 cubes.
Cube's size = 0.01f
They scattered around a plane size = 5*5 (w*h)
I got 20fps.
The profile result states that Bullet Physics is the bottleneck.

Second Experiment
1,000 cubes
size = 1.0f
They scattered around a plane size = 500*500
I got >> 60fps.

The cause (my guess)
It must be Bullet's boardphase aabb culling.
In the first experiment, many cubes probably fall into the same slot of boardphase's grid.

Question
Are there any way to guide Bullet's boardphase about my world scale?

I have read :-
boardphase : http://www.bulletphysics.org/mediawiki- ... Broadphase
btDbvtBroadphase : http://www.bulletphysics.org/mediawiki- ... _aabb_tree
scale the world (unrelated) : http://www.bulletphysics.org/mediawiki- ... _The_World

Edit: No one answer.
I doubt that I didn't do research enough / my question is unclear, too easy, not interesting /
or no one know the answer? :(

Edit2: I am very satisfied with drleviathan's answer, so I marked it as solved for now. Thank!
Last edited by hyyou on Sat Sep 16, 2017 2:03 am, edited 1 time in total.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: scale the world up 100x -> performance increase 3x

Post by drleviathan »

My guess is that the "collision margin" feature on the shapes expands their bounding box. If you aren't setting the collision margin manually then you're using the default margin (which is 0.04m!). Meanwhile, it appears that the broadphase data structure also has a hard coded default margin (look for DBVT_BP_MARGIN in the codebase -- I assume you're using the btDbvtBroadphase class) which is 0.05m. In short, the aabb of each object is larger than you think, and in the tiny-case it is relatively much larger than the large-case. More overlaps means more narrowphase evaluations means more CPU costs.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: scale the world up 100x -> performance increase 3x

Post by hyyou »

Thank drleviathan. This is a very reasonable guess.
cameron
Posts: 2
Joined: Fri May 06, 2016 9:18 pm

Re: [solved] scale world 100x -> performance increase 3x

Post by cameron »

IIRC, there is also a contact processing threshold that further expands the bounding boxes by a small amount
Post Reply