Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: OpenGL rendering pauses when heavy background task running

I am rendering objects via OpenGL, and got a nice smooth framerate of 60fps in most situations. UNTIL I do something heavy in a background thread, like fetching stuff from a REST API, processing it, and adding objects to the graph (low-priority stuff, I care more about UI fluidity). The renderer will then pause for a very long period, up to 1 second (ca. as long as the background thread runs), and then resume as if nothing had happened. I noticed this because an animation is started at the same time, and it gets stuck for this period. The background thread is set to minimum priority, and garbage collection does take up to 100-200ms, but not the whole second. When I set a debug point anywhere in the background task, rendering continues just fine, without any delays.

Is it possible that my heavy background thread starves the OpenGL thread? If so, what can I do?

like image 418
manmal Avatar asked Jun 27 '12 13:06

manmal


1 Answers

Of course! A GPU needs to be fed data, and that's done by the CPU. So, if something in the system bottlenecks, like I/O or CPU processing, then the GPU can't get fed. For example, animation is traditionally done on the CPU. This is why you get a lot of games on the PC getting higher frame rates with the same graphic chips but with different CPUs.

I also agree that profiling is a very good idea. If you can, I would suggest profiling to make sure it's actually the REST call, or if the REST call is one of many things

One thing I noticed about REST processing, and this happened to me. Since REST sometimes processes a lot of strings, and if you don't use StringBuilder, you can end up firing off a lot of garbage collection. However, it doesn't sound like you are getting this.

like image 200
Joe Plante Avatar answered Oct 04 '22 00:10

Joe Plante