Yes, 400+ joints is quite a few. If I'm reading those numbers right it's taking 20ms or more every frame to calculate what impulses should be given to the bodies (mostly) so that the joint constraints can be met. That limits you to 50fps before you've even done anything else, and is about what I would expect from iOS hardware.
Understanding Testbed profiling (using DumpShell.h)
General DiscussionHere is what Instruments (Time Profiler) shows, for 6 minutes and a half (ordered by running time).

Looks like the joints are consuming most of the time. I'm not sure how can I improve this.
I'll try to use fewer joints but still, I'm thinking is possible to make some configurations for the bodies that form the compound shape to be faster, since those are actually part of a special "group" of bodies that shouldn't collide or shouldn't have any contact with each other (even though they actually touch each other).
I mean box2d should be told somehow that it shouldn't check for contacts and other stuff between those bodies (like you said earlier "to cut out unnecessary calculations"). Not sure if it's possible, I do use collideConnected=false for all the joints in the compound shape.
Thanks for your answer guys! @pTymN I really appreciate your help with this.

Looks like the joints are consuming most of the time. I'm not sure how can I improve this.
I'll try to use fewer joints but still, I'm thinking is possible to make some configurations for the bodies that form the compound shape to be faster, since those are actually part of a special "group" of bodies that shouldn't collide or shouldn't have any contact with each other (even though they actually touch each other).
I mean box2d should be told somehow that it shouldn't check for contacts and other stuff between those bodies (like you said earlier "to cut out unnecessary calculations"). Not sure if it's possible, I do use collideConnected=false for all the joints in the compound shape.
Thanks for your answer guys! @pTymN I really appreciate your help with this.
Looks like you might need a different strategy for whatever it is you're making. Is there any way you could:
- cut down on the number of joints
- make some bodies inactive
- make the weld-joined bodies part of the same rigid body
- reduce the island sizes
- cut down on the number of joints
- make some bodies inactive
- make the weld-joined bodies part of the same rigid body
- reduce the island sizes
Thanks @irresistible force
I'll try to do that. But I'm not sure I know how to "reduce the island sizes". Also if I make the weld-joined bodies part of the same rigid body doesn't that mean I'll end up with a big rigid body instead of many stretchy small bodies ?
I'll try to do that. But I'm not sure I know how to "reduce the island sizes". Also if I make the weld-joined bodies part of the same rigid body doesn't that mean I'll end up with a big rigid body instead of many stretchy small bodies ?
Most of my Box2D optimizations went into the contact solver, not the joints. Having 400 joints active is killing your CPU. Are you using weld joints to attempt to connect shapes rigidly? Box2D allows for multiple collision shapes per body. So maybe you could eliminate most of those joints.
I see. Actually I'm using weld joints for connecting shapes softly 🙂 I am using the frequency and damping, and they work really nice, the simulation looks natural.
Before, I was using revolute joints instead of weld joints, but weld joints are better for 2 reasons: I want the frequency / damping, and they provide better performance than revolute joints, for some reason.
Sadly I can't eliminate those joints. And for this reason I can't really use this solution, although I really like how the simulation looks. The performance is too bad to be used on iOS devices (especially iPhone 3GS, I'm not targeting lower than that).
Thanks for your answer though Erin! Hope you'll have a great time at GDC
Before, I was using revolute joints instead of weld joints, but weld joints are better for 2 reasons: I want the frequency / damping, and they provide better performance than revolute joints, for some reason.
Sadly I can't eliminate those joints. And for this reason I can't really use this solution, although I really like how the simulation looks. The performance is too bad to be used on iOS devices (especially iPhone 3GS, I'm not targeting lower than that).
Thanks for your answer though Erin! Hope you'll have a great time at GDC
Original thread: https://box2d.org/forum/viewtopic.php?t=8177