13

My game uses too much battery. I don't know exactly how much it uses as compared to comparable games, but it uses too much. Players complain that it uses a lot, and a number of them note that it makes their device "run hot". I'm just starting to investigate this and wanted to ask some theoretical and practical questions to narrow the search space. This is mainly about the iOS version of my game, but probably many of the same issues affect the Android version. Sorry to ask many sub-questions, but they all seemed so interrelated I thought it best to keep them together.

Side notes: My game doesn't do network access (called out in several places as a big battery drain) and doesn't consume a lot of battery in the background; it's the foreground running that is the problem.

(1) I know there are APIs to read the battery level, so I can do some automated testing. My question here is: About how long (or perhaps: about how much battery drain) do I need to let the thing run to get a reliable reading? For instance, if it runs for 10 minutes is that reliable? If it drains 10% of the battery, is that reliable? Or is it better to run for more like an hour (or, say, see how long it takes the battery to drain 50%)? What I'm asking here is how sensitive/reliable the battery meter is, so I know how long each test run needs to be.

(2) I'm trying to understand what are the likely causes of the high battery use. Below I list some possible factors. Please help me understand which ones are the most likely culprits:

(2a) As with a lot of games, my game needs to draw the full screen on each frame. It runs at about 30 fps. I know that Apple says to "only refresh the screen as much as you need to", but I pretty much need to draw every frame. Actually, I could put some work into only drawing the parts of the screen that had changed, but in my case that will still be most of the screen. And in any case, even if I can localize the drawing to only part of the screen, I'm still making an OpenGL swap buffers call 30 times per second, so does it really matter that I've worked hard to draw a bit less?

(2b) As I draw the screen elements, there is a certain amount of floating point math that goes on (e.g., in computing texture UV coordinates), and some (less) double precision math that goes on. I don't know how expensive these are, battery-wise, as compared to similar integer operations. I could probably cache a lot of these values to not have to repeatedly compute them, if that was a likely win.

(2c) I do a certain amount of texture switching when rendering the scene. I had previously only been worried about this making the game too slow (it doesn't), but now I also wonder whether reducing texture switching would reduce battery use.

(2d) I'm not sure if this would be practical for me but: I have been reading about shaders and OpenCL, and I want to understand if I were to unload some of the CPU processing to the GPU, whether that would likely save battery (in addition to presumably running faster for vector-type operations). Or would it perhaps use even more battery on the GPU than on the CPU?

I realize that I can narrow down which factors are at play by disabling certain parts of the game and doing iterative battery test runs (hence part (1) of the question). It's just that that disabling is not trivial and there are enough potential culprits that I thought I'd ask for general advice first.

jimmym715
  • 1,512
  • 1
  • 16
  • 25
M Katz
  • 5,098
  • 3
  • 44
  • 66
  • I know you said it's mainly the ios version, but the android version doesn't have ads? Even if you aren't using network explicitly, is there anything that could be using it in the background? – Michael Apr 20 '12 at 02:49
  • 2
    Additionally, if you're ok with reading research papers [this](http://research.microsoft.com/en-us/people/mzh/eurosys-2012.pdf) just came out from a recent conference. It's all Android, but maybe this will give you some idea how other people have done power measurements. – Michael Apr 20 '12 at 02:51
  • Michael, thanks for the reference. I've read over the paper and I'll look at it more closely. It doesn't appear that the eprof tool is available for download at this point. (?) But maybe I can glean enough insights from the paper to point me in the right direction. In answer to your other question, no, I'm not showing ads. – M Katz Apr 20 '12 at 03:15

2 Answers2

2

Try reading this article: Android Documents on optimization

What works well for me, is decreasing the use for garbage collection
e.g. when programming for a desktop computer, you're (or i'm) used to defining variables inside loops when they are not needed out side of the loop, this causes a massive use of garbage collection (and i'm not talking about primitive vars, but big objects.

try avoiding things like that.

Vlad
  • 735
  • 2
  • 10
  • 19
  • Thanks, but I'm actually using Marmalade so my code is in native mode (at least all the code I have control over) so no garbage collection. And it's not an issue with Marmalade, since my other Marmalade apps don't have this problem. – M Katz Apr 22 '12 at 22:59
2

One little tip that really helped me get Battery usage (and warmth of the device!) down was to throttle FPS in my custom OpenGL Engine.

Especially while the scene is static (e.g. a turn-based game or the user tapped pause) throttle down FPS. Or throttle if the user isn't responsive for more then 10 seconds, like a screensaver on a desktop pc. In the real world users often get distracted while using mobile devices. Don't let your app drain battery while your user figures out what subway-station he's in ;)

Also on the iPhone, sometimes 60FPS is the default, throttling this manually to 30 FPS is barely visible and safes you about half of the gpu cycles (and therefore a lot of battery!).

Bersaelor
  • 2,517
  • 34
  • 58