开发者

Profiling and Optimizing a game android

I'm making my first Android game which is going to be a 3D arcade-ish game using opengl es. I've been working on it for quite a long time, mainly optimizing the engine for flexibility for the future.

Anyways now I'm completely done with the games features and all the pretty stuff, but it laggs on phones that AREN'T my debug phone. The game has pretty high-quality graphics for a mobile game so a little lagg is expected, but the difference in performance between running the game on a Nexus S and running it on a MyTouch 4G is huge. The game isn't even playable on lower-end phones like the LG Optimus(the game runs, but its too choppy to play comfortably). On my Nexus S I rarely if ever get choppy movement(I'开发者_StackOverflow社区ve implemented frame-rate independent movement in the game) but on the MyTouch 4G it is a lot more common, although the game is still playable....but annoying

I come from a desktop game-development background, and optimization has never been subject of interest for me before. What can you recommend to help me speed up the game?

I've tried optimizing code as much as I possibly could, and the performance has improved significantly, but there seem to be some things that I've missed or am overlooking. Its a huge game with a full engine and lots and lots of code.

I've tried tracking down all allocations and making sure they aren't deallocated or forgotten during runtime so that the GC doesn't get invoked while you are playing. Thats basically all I can think of doing, I don't know what else could make it lagg

And I doubt its the poly count of the meshes because even though they are high quality, I added an option in the game that lets you choose the quality of the graphics from Low, Medium, and High much like on a computer game, and the difference between Low and High are somewhere between 600-900 vertices! The only improvement I've noticed that gives is load time. Also there aren't any special post-processing effects, lighting, shaders, realtime SSS, or any of that. Just textured faces :P

also the "lagg" I'm reffering to are random freezes. I'm pretty sure they are the GC, but it could be something else since I think I've found and controlled all allocations(there are a lot). Since my game is frame-rate independent, whenever it unfreezes, the player and enemies and everything 'jumps forward' to keep up, and this makes an already difficult game a LOT more difficult!

I'm new to profiling, and optimization. How can I use the android debug tools(or other third-party tools) to get a better picture of how my game performs during runtime, and when/why it freezes so that I can fix them.

ALSO, bonus question :) : is there a way for me to see how it would perform on other phones without actually having the phones or knowing people who have them? Like, how fast would it go on a Droid X even though I don't have a Droid X nor does anyone I know


Have you tried profiling the code with traceview? insert

Debug.startMethodTracing("myfile");

in onCreate, then

Debug.stopMethodTracing();

where you want it to finish writing the file. To view the results, plug the device into the computer and run:

/path/to/android-sdk/platform-tools/adb pull /sdcard/myfile.trace
/path/to/android-sdk/tools/traceview ./myfile.trace

This will show what classes are taking more time. You may be able to optimize the slower classes, and/or move it to a background thread.

You mentioned it works fine in some phones, perhaps those are the newer phones with 24mb/app limit instead of 16mb/app limit? You might try the Memory Analyzer in Eclipse, to check for memory leaks or unnecessary large objects. To install, go to Help -> Install Software, and use

http://download.eclipse.org/mat/1.1/update-site/

Then, while you are debugging in DDMS view, select Dump HPROF File (The green glass with the red arrow), it should open the memory analyzer.

Edit -

It seems you need to convert the Android-hprof file now, as described here.


That's basically all I can think of doing. I don't know what else could make it lag.

A lot of people do that, which is to optimize by trying to think of things. That will take you part way, but only part way, especially if the software is large.

Actually, things in the code that take time expose themselves to discovery by snapshot. You don't need to think of them. You just let the program display them. Here's an example.


First of all take a closer look what logcat is saying. Maybe you'll find the answer for unwanted lag begviour. Secondly, if you want to check how often and how much time the methods executions takes just use DDMS. Don't know what kind of environment you're using, but there is an Perspective in Eclipse which has an option called "Start method profiling". Simply click on it, than wait couple of seconds and unclick it. After a few moments you'll get the overwhelming report. And the devices issue, let me cite: "If you want to know how your app performs on a given device, you need to test on that device." from [1]

[1] http://developer.android.com/guide/practices/design/performance.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜