www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: grog on April 19, 2011, 11:39:09 pm

Title: Collision allocations
Post by: grog 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.
Title: Re: Collision allocations
Post by: EgonOlsen on April 20, 2011, 07:58:35 am
Which version are you using? The latest beta or the "official" one?
Title: Re: Collision allocations
Post by: grog on April 20, 2011, 08:05:00 am
I am using the latest beta, I believe.  From the version updates thread on this forum.
Title: Re: Collision allocations
Post by: EgonOlsen on April 20, 2011, 08:14:55 am
It shouldn't allocate that much objects then...are you using CollisionListeners/-Events?
Title: Re: Collision allocations
Post by: grog 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:
Title: Re: Collision allocations
Post by: EgonOlsen 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...
Title: Re: Collision allocations
Post by: grog 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.
Title: Re: Collision allocations
Post by: EgonOlsen 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...
Title: Re: Collision allocations
Post by: EgonOlsen 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.
Title: Re: Collision allocations
Post by: grog on April 22, 2011, 01:47:54 am
Thank you, Egon.  That's much better.