-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile bullet with threadsafe switch on #53183
Conversation
What downsides does the |
According to this benchmark, there is around a ~3% penalty in single-thread performances due to this change. Side note: I noticed by looking at the code that Bullet has a hard limit on the number of threads that can access it as it keeps track of them, and it is now set to 64. |
358321f
to
6f81c21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great change, thanks!
Having a 3% tradeoff on single-threaded raycasts doesn't seem too bad, given that in extensive usage you can now use threads to make it much faster.
I've run some general tests with the physics simulation, and didn't spot any performance drop or other issue.
If anything, it seems adding/removing objects in the broadphase is a little bit faster, but I have no idea why :)
Keep in mind that I only tested it with parallel raycasting. You can have many threads doing raycast at the same time (which is what I do) but that can't happen during the physics engine update. To support that, I have a node that runs last and accumulates requests of executing tasks from other nodes. Then, when it's its turn to run I know there are compilation macros to enable parallel constraint resolution (which I think also require this flag), but that requires more changes to the glue code. Maybe I'll give it a try to enable that too . |
There was an effort in the past to try and enable multi-threaded physics in Bullet, but it got stalled because of lack of time, after the first results didn't confirm the performance improvements we expected. This is @fire's PR, it should be good to start testing if you're interested: |
Thanks! |
Actually, even if Bullet is disabled on master, it would be good to port this change to keep branches in sync. Would you like to take care of it @m4nu3lf? Otherwise I don't mind doing it. |
I've included a cherry-pick of this commit in this PR for |
Compile Bullet with the BT_THREADSAFE switch so that it is thread-safe to raycast from multiple threads (as long as the physics engine is not stepping).
I'm using this feature in my project to implement projectile rayscan and visibility checks.
Making this for 3.x first as Bullet seems to not be compiled yet when compiling from master.