iPhone performance issue

I'm currently working on a project using Box2D on the iPhone, and I'm noticing a performance bottleneck, which I think is coming from the physics calculations. The project uses the accelerometer for gravity, and so the following issue has come up: when a number of objects ( i would say about 30 to 35) are created in the world, they are able to run at the maximum fps (I cap at 30) with no problem when there is no gravity (phone flat) and they float freely; however, when there is more gravity and they bunch up at the bottom of the screen, the framerate drops dramatically. I think this just has to do with the way Box2D reduces the number of collision checks it has to do (when the objects are floating freely, it is doing less object comparisons), but I was wondering if there was any way of improving the performance even when the objects are bunched up. I haven't tried changing the number of iterations (I'm using 10), so I'm guessing that's probably the best way of improving the performance with larger numbers of collisions.

Thanks for input 😀.
1) Make sure you've disabled "Compile for Thumb" - see http://blog.sapusmedia.com/2008/12/comp ... thumb.html, the gist is that Thumb compilation alters the instruction set for better space performance at the cost of floating point speed (single floating point ops end up translated to multiple ops so that each op takes up less space). This can make a substantial difference, and you should never use Thumb compilation if you're doing anything with heavy floating point work.

2) Try running in "Release" mode, see if there's a difference. Sometimes this helps.

3) You may be able to get away with 5 iterations instead of 10.

4) At 30 fps, I would think that you could simulate 35 objects all touching, but I could be wrong, I've never actually stress tested the iPhone. Be careful, though - one thing I have noticed with the device is that a lot of strange stuff can bottleneck you in ways that you really wouldn't expect, and which can be tough to track down (things like putting UI elements on top of OpenGL displays, inefficient handling of accelerometer updates or touch events, drawing itself (the pixel fill rate is not great on this thing, even though it can handle a lot of polys), etc.).

5) When you run in the simulator, do you have similar issues?
Hey, thanks for the thumb trick; that plus release mode increased the performance to about 60 objects before the framerate moves (from 30) 🙂. That's still with the iterations at 10; I haven't noticed too much performance difference with changing the iterations, for some reason.

I know what you mean by strange bottlenecks on the iPhone xD.

The simulator doesn't have a problem with performance at all; I can add near infinite objects without any performance difference. Too bad the simulator doesn't simulate the performance of the actual device too well xD.

Anyway, thanks for the tips 🙂.

Original thread: https://box2d.org/forum/viewtopic.php?t=1962