Profiling, excessive calls to clearHashCell

Official forum for the Chipmunk2D Physics Library.
Post Reply
yarri
Posts: 2
Joined: Mon Jan 26, 2009 4:29 pm
Contact:

Profiling, excessive calls to clearHashCell

Post by yarri »

Hi,

Nice work on the engine, we've been trying it for a mini-game in our iPhone app and started profiling on the device. With about 100+ cpCircle bodies (think bubbles...) in a crude particle system we get a drop off from 30 fps to about 20 after 50 bodies; similar to the performance issues described in an earlier post:
http://www.slembcke.net/forums/viewtopi ... erformance

We resized the active hash with cell size of 50 with 9999 bins. Profiling the code on the device shows 21.2% thread time spent in cpSpaceHashQueryRehash and 14.6% of that in clearHash. Profile screen shot here:
http://twitpic.com/17kj2

Can you give some advice -- is this type of profile typical, don't the clear hash calls seem excessive? Is that due to too large a cell size, or too many bins, both?

Still experimenting...
--yarri
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Profiling, excessive calls to clearHashCell

Post by slembcke »

The excessive usage is due to having too many hash bins. With 50 bodies, you do not need 10,000 hash bins. 500, or 1,000 would probably do just fine. It's something you'll have to guess and check though. The reason why it clears the hash every time is that it came out faster to just clear the hash and start over than to try to update it incrementally when the hash table was fairly full.

The cell size defines how fine or coarse the grid of cells are. Make it too small and each object will have to be inserted into too many cells, make it too big and many objects will be inserted into a single cell. The more hash bins you have, the less likely it is that you will get false positives from two separate cells mapping onto the same hash bin.

A good rule of thumb that I start with is to set the cell size to size of the average object. That way most of your objects will map to less than 4 cells. For the number of bins, 10x the number of objects is a pretty good guess. Figuring that each object will map into 4 cells on average, that means that the loading factor of the hash table will be less than half, and that should be more than enough to greatly reduce the count of false positives.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests