Wednesday, September 26, 2012

Recent Update: Speed Fixes

Android Programming War Story -- Professor Cramwell's History Upgrade 1

After we began testing Professor Cramwell's History on a number of devices we noticed that there were performance problems on low-end, single core smartphones such as the LG Optimus 1 (a 2-year old phone, but one we still wanted to support). On this particular phone the time between one question being answered and the next to fully appear was around 13 seconds, totally unacceptable.

After analyzing the data it became obvious that the problem was long running operations on our Sqlite database.

I realized that I had mistakenly left one of the database update operations on the OpenGL Graphics thread. Shunting that operation to the background thread cut the wait time in half, but that still wasn't enough.

Part of the problem may have been that the thread was relatively low priority, but that thread has to be low priority to keep the Open GL Thread running at full speed so the graphics stay as smooth as possible. So changing the thread priority was not an option.

Finer grained analysis of the database operations led to the isolation of the problem to a key query that set up stats and another query that selects questions based on the user stats. I disabled these two queries for single core phones, putting in substitutes that rely on randomness instead. While not ideal, speed was more important in this case. This optimization is only active for single-core phones.

Final Time: 2 seconds between questions on a 2-year-old,single-core smartphone running around 600mhz.

int AvailableProcessors=Runtime.getRuntime().availableProcessors();
--Tomaz

No comments:

Post a Comment