Author Topic: Performance degradation  (Read 2075 times)

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Performance degradation
« on: May 19, 2011, 05:21:01 pm »
Hi again,

I have a very strange situation in which I am getting a serious performance degradation, from the game being smooth to almost unplayable in terms of FPS.

I have multiple scenarios that can be loaded and played, then unloaded. For convenience each one of those uses a World object and also takes care of loading textures and objects3D.

The first time I load a scenario, it works fine, but if I keep loading scenarios the performance is seriously impacted, and I can not see why.

On the unload of each scenario I am flushing the textures and removing all the objects from the world, the memory footprint does not grow over time, so I assume there are no leaks or lost object.

Can you give me a hint on what can be causing it?

Thanks a lot.

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Performance degradation
« Reply #1 on: May 19, 2011, 06:36:30 pm »
This may be a hint, but I removed the Overlays completely and this degradation has disappeared almost completely.

It does not make a lot of sense since I was calling dispose every time the overlay was no longer used.

In addition to that, the Overlay is "supposed" to be linked to the World, so changing worlds should not impact it, or at least I don't see a reason why it should.

So, I suspect the Overlay dispose method is not working as expected, and eventually a lot of overlays were drawn on screen slowing everything down.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Performance degradation
« Reply #2 on: May 20, 2011, 12:14:20 am »
dispose() seems fine to me...it removes the Overlay from the world, nulls some additional stuff...should be fine actually. Can you create a simple test case to reproduce this?

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Performance degradation
« Reply #3 on: May 20, 2011, 09:33:57 am »
I will try to create a simple example. I am using the version of the library you uploaded on this thread (in case it makes any difference)

http://www.jpct.net/forum2/index.php/topic,1907.0.html

Anyway, there should be something else, because on the long run it still shows some performance degradation without the overlay but it takes much longer to notice.

With the overlays in 3-4 iterations it was unplayable, now it takes around 10-12 to make it noticeable.

I'll come back to you later with a simplified example. Thanks a lot!

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Performance degradation
« Reply #4 on: May 20, 2011, 01:43:34 pm »
I am uploading the apk for the test, basically it has a button to reload the scene, and a FPS counter. It is here: http://android.shalafi.net/PerformanceTest.apk

The scene is a room with a sphere in the middle, the camera is going around it. There are 4 overlays on the top

Each time you clean the scene, there is a drop in the fps rate. For me it starts in 55-60 and after a few clicks it goes to 30-35, and visually it is very laggy while it is smooth at the beginning.

In addition to that, the overlays blink a lot, but that is a separate problem.

Also, if I remove the overlays, the performance suffers but a lot less.

Maybe I am doing something wrong. The code for the click on the button is as follows
Code: [Select]
public void onClick(View arg0) {
synchronized (mWorld) {
mWorld.removeAllObjects();
for (int i=0; i< mOverlays.length; i++) {
if (mOverlays[i] != null) {
mOverlays[i].dispose();
}
}
TextureManager.getInstance().flush();

Texture texture = new Texture(getResources().openRawResource(R.raw.texture), true);
TextureManager.getInstance().addTexture(TEXTURE_NAME, texture);
TextureManager.getInstance().addTexture(OVERLAY_TEXTURE);

Object3D [] model = Loader.load3DS(getResources().openRawResource(R.raw.model), 1);
for (int i=0; i<model.length; i++) {
model[i].setTexture(TEXTURE_NAME);
mWorld.addObject(model[i]);
}
for (int i=0; i<mOverlays.length; i++) {
mOverlays[i] = new Overlay(mWorld, i*60, 0, i*60+50, 50, OVERLAY_TEXTURE);
}
mCurrentTime = 0;
}
}
« Last Edit: May 20, 2011, 01:48:45 pm by shalafi »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Performance degradation
« Reply #5 on: May 20, 2011, 03:11:34 pm »
Why are you loading the textures over and over again? Loading them once should be sufficient. If there is a reason for this, make sure to remove them from the GPU too (flush() doesn't do this). Use this method in addition: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/TextureManager.html#removeAndUnload(java.lang.String, com.threed.jpct.FrameBuffer)

But as said: Try to avoid loading them on each click...it's not needed at all. If this is responsible for the slow down...i'm not sure. If it doesn't help, try to set Config.unloadImmediately=true in addition. Still no luck, then i would like to see the complete source code of the test case to debug this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Performance degradation
« Reply #6 on: May 20, 2011, 03:25:28 pm »
On Nexus S, i'm not seeing any Overlays at all. I'm also not getting any rendering until i press clean once. But then, i can't verify the performance problem. It runs at the limit of 56 fps all the time (pressed clean maybe a dozen times)... ???

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Performance degradation
« Reply #7 on: May 21, 2011, 08:49:59 am »
This is just the smallest test I could put together showing the problem. I need to unload the textures because we change from one scenario to the other and they don't share the textures, if we keep them in memory it is a waste.

Maybe the Nexus S has a better implementation of OpenGl, or just more memory or a faster processor. In my Nexus one each time I press the button I can see a drop in t he fps or 1-2, so iin 12 clicks it can easily be at 45 fps in my phone.

I'll try your tips and let you know if they worked. Thanks!

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Performance degradation
« Reply #8 on: May 23, 2011, 09:20:54 am »
Ok, so not flushing the TextureManager and reusing the texture solved the degradation problem, I guess doing a proper unload will fix it as well, but I have to test it.

Thanks