Java – FPS throttling (?) – Make your phone’s update/drawing cycle smoother?

FPS throttling (?) – Make your phone’s update/drawing cycle smoother?… here is a solution to the problem.

FPS throttling (?) – Make your phone’s update/drawing cycle smoother?

I’m building an app for Android Phone and I’m experiencing some weird “throttling”. I believe this is because semaphores are being called to stop whatever the app is doing to process other content in the phone. Although I am not positive.

I’m curious if there’s a way to spread out these interrupts or something else to reduce the user’s visibility into the application with little to no latency spikes.

EDIT: For some further information, what I’m currently running is a two-dimensional image array — only about 80 images are drawn when ~8000 is instantiated. They are drawn only if their hue is not RGB0 (dark black). The runtime loop in the update checks which images are closest to the player and gives them a basic minimum lighting of RGB 0.2f. In addition, basic event handlers and the move/viewport loop are also being updated. Note that I’m using the Libgdx framework, not android native. So OpenGL and so on and so forth

EDIT: I would like to point out that the problem is not what you think. I send a vector2 about 3800 renders – but instead of just “sending” one, I declare a new Vector2 and send the parameters that way. Garbage collectors will not tolerate such atrocities. Now I only send 2 floats and it runs smoothly. My bad._.

Solution

This should not happen unless there are multiple activity processes running at the same time.

My guess (didn’t see the code) is that the garbage collector kicks too much. Do you initialize objects in a loop? If so, can you reuse these objects?

An object can be anything, especially a View. Be sure to reuse your View instead of creating a new View.

Another point to consider is full layout redraw: can you redraw only part of the screen instead of all of it? (i.e., use view.invalidate(rect); instead of view.invalidate(); )

Finally, is your layout too deep? Try to smooth them out. For example, use RelativeLayouts instead of nested LinearLayouts.

Take a moment to watch this video: Romain Guy’s Google I/O 2009 talk.

After the update, I see that you have 8K pictures to draw. If you instantiate them all, chances are there isn’t much room in memory for anything else, so the GC will need to constantly collect whatever it can collect. This means slowing down the entire system. Check out about 53-55 minutes of Q&A in the same video. He suggests, in cases like yours, put all references to bitmaps in a soft-referenced HashMap so that the GC can collect unused images when needed. This will prevent any other things from being collected.
I also instantiate them in batches as needed, rather than instantiating them all at the beginning.

Related Problems and Solutions