How to improve performances?

Official forum for the Chipmunk2D Physics Library.

How to improve performances?

Postby mentalray » Wed May 20, 2009 9:56 am

Hi,

I'm almost done porting my game from ODE to Chipmunk. My primary objective was to improve the performances. Since ODE is a 3D physics library, there are useless computations for the extra dimension. Also, I'm doing a lot of gymnastics to prevent the objects from rotating and/or translating in the 3rd dimension. I was convinced that using Chipmunk would improve the performances drastically.

Well, I've been surprise so far, but not in the good sense. ;) The game is very much slower using Chipmunk (I'd say about 2x to 3x slower).

That said, there must be something that I can do to improve and surpass ODE's performances. A typical configuration has about 25 active blocks and 50 static blocks. There are very few joints (<10). I could use segments instead of blocks for the static environment, but I don't want to try this unless I'm sure that the performance gain is worth it.

I think the reason why ODE performs better may be related to the space hierarchy it supports. You can add space inside other spaces, which will improve the collisions detection if done properly (the object should intersect with the bounding-box of a space before trying the individual objects of that space). Is there a way to do something similar with Chipmunk?

I have played with many factors, including the number of iterations, the hash sizes, etc. I get either a slow simulation, or an unstable one.

The platform is the iPhoneOS.

Any idea would be helpful. Thanks all.
mentalray
 
Posts: 12
Joined: Wed May 13, 2009 8:19 pm

Re: How to improve performances?

Postby slembcke » Wed May 20, 2009 11:57 am

Have you tried running shark to tell you where the CPU time is being spent? What compiler flags are you using?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: How to improve performances?

Postby mentalray » Wed May 20, 2009 10:59 pm

I got interesting results with Shark. Most of the time is spent in cpArbiterApplyImpulse (12.7%). For some weird reason, cpv is second place with 8.5%.

The configuration that gave these results consist of about 50 static blocks, a dozen active blocks and 8 joints.

When in release mode, I compile with -O3, but that doesn't seem to help very much.

Thanks for your time.
mentalray
 
Posts: 12
Joined: Wed May 13, 2009 8:19 pm

Re: How to improve performances?

Postby mentalray » Wed May 20, 2009 11:17 pm

Arrrrgh! I feel so stupid now.

There was a situation that caused static objects to be added in the active space. No wonder why it was so slow. A tiny fix did it, it's now super fast!

It's actually quite impressive that Chipmunk was able to get a quite respectable framerate with so many active objects. Impressive.

I'm sorry for the inconvenience.
Thanks all!
mentalray
 
Posts: 12
Joined: Wed May 13, 2009 8:19 pm

Re: How to improve performances?

Postby slembcke » Thu May 21, 2009 1:35 am

If you are getting cpv() in the trace it's because it's not compiled with inlining enabled. That should actually be a pretty sizable performance hit. You should also make sure that you are compiling with the -ffast-math flag and that you are disabling thumb compilation at least for the Chipmunk sources. Enabling both of those will probably give you another very sizable bump in speed.

Depending on how many static shapes you had, that would have been a pretty sizable performance hit. Recalculating all the cached collision data, bounding boxes, and rehashing shapes that never moved and all. ;)

Out of curiosity, how does it compare now? I've actually never attempted to compare Chipmunk to ODE or another 3D physics engine in terms of speed. One of the original reasons why I started writing a 2D physics engine was frustration with trying to use ODE to run 2D physics. It seemed like there had to be a nice simple 2D library out there. Unable to find one, I decided to try to write one. I never really looked back to compare performance because that wasn't a big deal to me.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: How to improve performances?

Postby mentalray » Thu May 21, 2009 8:26 pm

Yes, I ran shark on a debug version of the software, this is probably why the cpv() calls where there (is there a way to see the symbols in shark while compiling in release?)

My quick and unscientific tests show that Chipmunk is roughly 4x faster than ODE, which is very impressive. I wasn't expecting that kind of speedup. I'm really thrilled right now.

Congrats for your great library, it simply rocks.
mentalray
 
Posts: 12
Joined: Wed May 13, 2009 8:19 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests