Author Topic: Collision allocations  (Read 3954 times)

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Collision allocations
« on: April 19, 2011, 11:39:09 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision allocations
« Reply #1 on: April 20, 2011, 07:58:35 am »
Which version are you using? The latest beta or the "official" one?

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Collision allocations
« Reply #2 on: April 20, 2011, 08:05:00 am »
I am using the latest beta, I believe.  From the version updates thread on this forum.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision allocations
« Reply #3 on: April 20, 2011, 08:14:55 am »
It shouldn't allocate that much objects then...are you using CollisionListeners/-Events?

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Collision allocations
« Reply #4 on: April 21, 2011, 07:52:25 pm »
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()

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision allocations
« Reply #5 on: April 21, 2011, 09:53:14 pm »
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...

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Collision allocations
« Reply #6 on: April 21, 2011, 10:49:46 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision allocations
« Reply #7 on: April 21, 2011, 11:03:37 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision allocations
« Reply #8 on: April 21, 2011, 11:34:19 pm »
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.

Offline grog

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Collision allocations
« Reply #9 on: April 22, 2011, 01:47:54 am »
Thank you, Egon.  That's much better.