Collision allocations

Started by grog, April 19, 2011, 11:39:09 PM

Previous topic - Next topic

grog

I am working on a little project and I noticed that the GC seems to be running every couple of seconds and causing noticeable stuttering despite my efforts to avoid object allocations.  Using the Dalvik allocation tracker, I see that many objects are being allocated during runtime by the ellipsoid collision detection methods (Object3D.checkForCollisionEllipsoid).  Has anyone else encountered similar problems and can offer a solution or workaround to cut down on GCs?  I would hope to avoid it, but might switching to spherical or ray-polygon collisions result in fewer allocations?  Thanks in advance.

Also, since this is my first post here, I would like to say thank you to Egon for this wonderful engine.

EgonOlsen

Which version are you using? The latest beta or the "official" one?

grog

I am using the latest beta, I believe.  From the version updates thread on this forum.

EgonOlsen

It shouldn't allocate that much objects then...are you using CollisionListeners/-Events?

grog

No, I am not using any collision listeners.  I have a simple mesh loaded as a map (two cubic rooms with a couple of corridors between them) with an octree, and a couple of meshes for players within it.  I'll list what seems to be getting allocated for each iteration:

  • Plane and SimpleVectors in World.doWorldCollisionEllipsoid()
  • int[] and Object[] in OcTree.getColliderLeafs()
  • SimpleVector in World.checkObjCollisionEllipsoid()
  • SimpleVector and CollisionInfo in World.checkSomeCollisionEllipsoid()
  • Matrix in cloneMatrix() called from Object3D.getWorldTransformation() in ellipsoidIntersectsAABB()

EgonOlsen

Ellipsoid collision detection does create some objects and it's close to impossible to avoid this. It shouldn't be much of a problem though. Maybe getColliderLeafs() is a bit of a problem...i haven't optimized that one so far, because i never used octrees on Android. I'll look into it...

grog

Thanks.  The performance is roughly the same if I remove the octree.  If it is normal to expect a GC every two seconds or so, I suppose I can live with it.  I understand that some allocations are unavoidable.  The framerate is good beside the little stutter at each GC. I'll just hope that the stuttering doesn't get out of hand as more objects are added.

EgonOlsen

Something is fishy with this Matrix-cloning. It actually shouldn't happen that often...i've written a test case and am investigating this issue now...

EgonOlsen

I've updated the version thread with a download for a new beta version. This one should fix the problem with the matrix cloning while (hopefully) creating the same output. In addition, i applied some minor optimizations to reduce Plane and SimpleVector creations as well as int[] and Object[] creations in OcTree. It might be possible to reduce SimpleVector and CollisionInfo creations some more, but at least on Android 2.3, it's not an issue. The only thing i get in my test app are concurrent gcs every 10 seconds or so that pause the system for around 8ms.

P.S.: Make sure that you did a call to World.setDefaultThread(Thread.currentThread()); once in the thread that does the collision checking.

grog

Thank you, Egon.  That's much better.