Optimization help!

hi guys. Can anyone help me with this?

We’re currently optimizing our iphone game. We’ve done so much, from reducing poly count, to drawcalls, to fixing our script codes. This forum has been a lot of help but it seems that even after I’ve read the entire forum back-to-back, i can’t reach 30 fps. here are my stats:

iPhone Unity internal profiler stats:
cpu-player>    min: 25.7   max: 54.7   avg: 39.5
cpu-ogles-drv> min:  1.3   max:  8.9   avg:  3.4
gpu>           min: 15.4   max: 23.3   avg: 20.3
cpu-present>   min:  0.3   max:  5.2   avg:  1.4
frametime>     min: 29.8   max: 88.6   avg: 50.9
draw-call #>   min:  17    max:  35    avg:  28     | batched:    14
tris #>        min:  2653  max: 10564  avg:  7905   | batched:   546
verts #>       min:  1457  max:  5187  avg:  3930   | batched:   285
player-detail> physx:  4.8 animation:  4.9 culling  1.5 skinning:  0.9 batching:  0.1 render: 14.5 fixed-update-count: 0 .. 2
mono-scripts>  update:  2.9   fixedUpdate:  4.8 coroutines:  0.1 
mono-memory>   used heap: 380928 allocated heap: 479232  max number of collections: 1 collection total duration:  5.7

can anyone suggest on how we can reach 30? we’re currently running on 22 fps using the FPS counter posted somewhere here…

thanks guys.

you have a massive frametime. You can get at very best 20fps with that and that only if nothing else than the rendering would go on.

Sure you are doing your best on the textures end (not too large, not too many small ones) and use the best possible shader (no alpha test, single pass) and light setup

thanks for the suggestion dude. I’m going to have a talk with the artists and ask what they can say about what you just posted.

we’re using vertexlit or transparent/cutout/vertexlit on all but 1 material. we have 1 point light, and our average image size is at 128x128 for guis and textures (around 14 files in total), 2 512x512 for the environment. And we’re using bitmaps for fonts.

Any suggestions on how to bring down that frametime? :slight_smile:

That’s not so great for performance…use the non-cutout shaders instead.

–Eric

woah didn’t know that. I’m going to try that now…

Still no dice. Aside from the alpha clipping everywhere, my frame time went > 30 (30-40). :frowning:

if this keeps up, we’ll have to ship it at 22fps on an iTouch 2g.

You should take some time to browse the forum page you’re posting in.

have you tried checking for perf problems by removing elements of the game. for instance i would remove the light and see if that helps. I see you are cpu bound but you should not assume a gpu feature doesnt take cpu and check it also.

you want as few textures as possible. if possible combine textures into an atlas, it sounds like you are already doing this but again you should try replacing a group of textures with the same texture and see if it helps. say replace all ui textures from their 128 to a single 512 shared by them all. yes it wont look right but see if that helps your perf any.

your animation time and your physics time could both be better. i would look at those for optimizations.
make sure your vertex influence in animation meshes is 1 if possible so there is less time spent on the cpu. your tri’s are not high but they are also not low… are you doing anything with them that would cause a cpu spike? like deforming them with a script? if so you should optimize those meshes to reduce cpu time spent deforming.

have you checked in xcode to make sure you are using the full 60 possible fps of the iphone? i think its under Kfps but i cant remember right now if that is the correct group.

also make sure you are running in release mode as debug mode does extra work and will hurt your cpu perf.

your coroutine time is very low which implies you are doing a lot of your game scripts on every frame. you may not need that and could make some scripts run every few frames instead.

do you have interpolation turned on for your rigidbodys? if so make sure its turned off on everything that doesnt desperatly need it. for instance i have it on for my player but off for enemies.

you should really think about finding a way to reduce your draw calls more. 17 as a min and 28 as an average is not very good for iphone. you said you have 128 textures for UI which implies they are all seperate elements. you could save by finding a way to combine your UI into fewer drawcalls. although the stats imply you dont need gpu performance you can become blocked on the cpu as it waits for gpu data… i really really doubt this is happening in your situation but it can happen in some situattions.

the frame of information you show is on a frame that your are running a garbage collection. that GC is taking 5.7ms. are you seeing the GC run very often? you want to avoid a GC as much as possible, if you are seeing it often then try to get rid of your GC churn and it will reduce your average frame time by the listed 5.7ms.
for most people this is not an issue but i have a mesh deformation feature that causes the Heap memory to churn a lot on one of my projects and it causes a GC about every 5 seconds. I just want to make sure you are not having this issue.

audio can cause performance issues and is not listed in the stats. try removing audio and see if the world gets better. if so then start looking into audio for a perf savings.

that is what is poping to mind to check out… more detail will help people understand your situation. maybe even screen shots of the problem area so they know the context. since you are ready to ship posting a screen shot cant cause harm unless you are under contract.

Thanks for the reply PHeck. I’ve done most of what you said but I’m going to detail them anyway, see if I’m doing something wrong or if there’s anything I could improve on.

Done this as I’ve read somewhere that light doubles my tris and more tris is bad. Nothing. It doesn’t even double it.

Done this either. Still nothing.

Do you mean setting the quality for skinnedmeshrenderer to 1 bone? if so, yep done that too.

Actually, we started with 11K tris. We have come to a point that we actually redid our main character and enemies so as to have < 1K each. The bone count for each was also initially high (about 29), but with the new ones, we have about 6 each. and, no, I’m not deforming them coz I’m too lazy to manipulate vertices. :smile:

Yup, done that too. Also changed the game loop to EVENT_PUMP_BASED_LOOP and kMillisecondsPerFrameToProcessEvents to 1.

Apparently I was. :smile:

sorry for the long posts. :sweat_smile:

I’m going to see what I can do about that GC today and experiment on the interpolation stuff. Right now only the player is turned on with the enemies turned off. I’m also going to try that coroutine stuff. I didn’t really do this at first cause the game on the older Unity was leaking when i do coroutines.

finally the audio. Hmm… I’m using uncompressed wavs for those except for the BGM which are OGGs. I didn’t really want to remove the audio cause 1. I need them, 2. I don’t know what to do with them if ever they are the cause.

Also, Were experiencing double tricounts (well, not double. about x1.75?). I read somewhere that It’s caused by bad UVs so I’m having the artists check their work with that. But if anyone know of any other reason for that, I’m all ears! :smile:

Oh and thanks for the posts! :cry:

well i dont know about “double” tri counts but you will see vert counts go up depending on how many hard edges you have and how your uvs are layed out or if you have two uv sets. make sure you artist check that the uv verts are welded together. i know that if you export a obj from maya into xsi and then back into maya the uv’s will look ok but they are actually all broken and each vert needs to have its uvs welded. (this can be done with a simple script). something to double check.

as for the sound… if it is part of the issue then somthing you can look at to help it is to look for sounds that repeat. playing a sound twice cost more than playing a single sound in a loop. the event to call the sound and play it cost more than just repeating teh same sound. at work we found a good savings by changing this and its on Xbox360 and PS3. it was in a different engine but its the same theory. we also looped our effects instead of destroying and creating a new muzzle flash each time.

be carefull of having lots of sounds playing over each other etc. if this is part of your problem then think about setting up a limiter to track how many sounds are playing and to keep the max number down etc.
really when it comes to sound there are creative things to help perf but first of all find a way to disable them all and see if it helps, if it doesnt then dont touch it :wink:

I ran into the same issue with coroutines causing memory issues. it was because i was using the “yield waitforseconds” method, when i change everything to use either a “invokerepeating” method or a “if (timelasped)” method it fixed the memory issue i saw. maybe its the same issue or you?

i tried disabling all sounds. Still nothing.

as with the case with “yield waitforseconds”, yeah that’s the one that’s causing the memory leaks for me. I’m currently using the “if (timeelasped)” method for stuff that needs to execute after an interval.

I’m also sharing to you guys the screenies we took to try and find out that “double” tricount issues. Thanks all.

latest stats:

iPhone Unity internal profiler stats:
cpu-player>    min: 27.0   max: 54.7   avg: 34.4
cpu-ogles-drv> min:  1.4   max:  5.6   avg:  2.1
gpu>           min: 26.2   max: 28.0   avg: 25.2
cpu-present>   min:  0.3   max:  1.9   avg:  0.8
frametime>     min: 31.4   max: 86.7   avg: 45.3
draw-call #>   min:  20    max:  22    avg:  20     | batched:    15
tris #>        min:  1654  max:  1666  avg:  1657   | batched:   615
verts #>       min:   962  max:   970  avg:   963   | batched:   370
player-detail> physx:  3.6 animation:  4.6 culling  1.3 skinning:  0.8 batching:  0.1 render: 11.6 fixed-update-count: 0 .. 2
mono-scripts>  update:  4.2   fixedUpdate:  5.1 coroutines:  0.1 
mono-memory>   used heap: 425984 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0

206651–7617–$alsdream_421.zip (200 KB)

Your render number is huge. May come from the shaders then.

From which iModel is it tested ?

The fact that you have this line in profiler stats tells me that you have ENABLE_BLOCK_ON_GPU_PROFILER enabled. That should be used ONLY to profile GPU times since it skews CPU time a lot.

Your GPU usage is good enough to run @ 30fps. Now you should turn ENABLE_BLOCK_ON_GPU_PROFILER off and profile without it.

I’m using vertexlit/transparent vertexlit shaders for all.

I turned off all debugging tools: profiler, fps counter, etc, and profiled using the Mac’s profiler… I got around to 28, average. I guess that is enough as the producer wants it sent to QA and for final gameplay adjustments.

Thanks all you guys for the help! I’ll be sure to notify you guys when the game comes out. Thanks!! :smile:

From below it looks like you are using music in OGG format which will use over 50% of your CPU to play. You need to switch to MP3 format. I’d disable your music and rerun your tests to see if that’s the problem.