Hi,
I am in the process of profiling and optimising our unity iphone game using the internal profiler. I have been through a lot of tips and tutorials but I was hoping I could still get away with a cheeky post for help as I am struggling to improve my framerate a bit.
Looking at the typical internal profiler output below, can you suggest where I should be looking to get the best improvement in performance. I am looking for stable 30 fps on iphone 1st gen ++..
iPhone Unity internal profiler stats:
cpu-player> min: 13.6 max: 51.2 avg: 30.2
cpu-ogles-drv> min: 2.8 max: 16.5 avg: 5.6
cpu-waits-gpu> min: 0.2 max: 0.4 avg: 0.3
msaa-resolve> min: 0.0 max: 0.0 avg: 0.0
cpu-present> min: 0.8 max: 9.0 avg: 1.8
frametime> min: 31.8 max: 62.1 avg: 42.0
draw-call #> min: 26 max: 37 avg: 30 | batched: 8
tris #> min: 4199 max: 6876 avg: 5157 | batched: 251
verts #> min: 2391 max: 3680 avg: 2973 | batched: 131
player-detail> physx: 1.9 animation: 1.5 culling 0.0 skinning: 1.7 batching: 0.1 render: 13.5 fixed-update-count: 1 .. 3
mono-scripts> update: 3.3 fixedUpdate: 3.5 coroutines: 1.6
mono-memory> used heap: 540672 allocated heap: 643072 max number of collections: 0 collection total duration: 0.0
Measures we have already taken:
- Severely reduced polycounts
- Removed particle FX
- Replaced almost all with “mobile” shaders
The next dreaded step is to try and reduce draw calls by using shared materials across objects, but this is one step we are new to and will take some time. So if there is anything else we should look judging by these stats please can you let us know.
Thanks,
Tom
The problem is code.
You have by far too much code, wasting 70% on the cpu-player
You definitely need to work on that end.
I guess you by error use many strings, work with tags, use FindXXX functions or GetComponent within update and alike which you should reduce to a minimum and cut whenever not needed or redesign the code to not need them
27ms on code is pretty high. 19 draw calls isn’t too bad, but reducing those will also give cpu time back, so fix up your draw calls best you can before optimising the hell out of the code.
with lights on you have 30draw calls average, is hippocoder thinks you could improve on drawcalls… are you pooling your items or doing a lot of destroy/instantiate ?
Thanks for your responses. That’s really helpful and not where I was going to look for issues. I had just watched this talk at Unity09 (http://download.unity3d.com/support/resources/files/Unite09_iPhone15.mov) and concluded that cpu-player was responsible for all aspects including rendering etc. not just code.
I do have a lot of instantiate/destroys involved in places, however there is some pooling so I will just extend that to accomodate the non-pooled objects.
I also have a lot of Updates and FixedUpdates, perhaps I’ll consolidate them into a few managers that update centrally every X frames, where X will be a public var I can tweak…
Does this sound like a sensible plan?
Cheers,
Tom
the udpates and fixed updates aren’t the heavy part it seems (they are exposed on their own but the cpu player is more than 4 times as large update + fixedupdate)
Thanks Dreamora,
Please forgive my denseness but I still don’t have a decent grasp of what is represented by the cpu-player stat and what I can do to reduce it.
If it is “code” but not the contents of the Update()/FixedUpdate() functions then I presume I should be looking for work by the Unity game engine. This would be things like:
- Searching through game objects via GameObject.Find() method use instead of FindXXX()
- Instantiating new objects
- Destroying objects
- … what else?
Should I just be looking to reduce the number of game objects present in the scene at any one time?
There is 3 stages to each level, each featuring a different set of game objects: start game scenery (large), mid-game objects (small, critical), end game objects (medium, critical). Perhaps I should start by looking at destroying the game objects that are present at the start of the level when they go off screen during game play and then reinstantiating them from a prefabs (or set of prefabs) when the game is restarted.
Thanks for your help.
Tom
PS Just so you know… After removing a bunch of key game objects that feature during the game, I got the following stats, which I think shows that is not where the bulk of the problem is…
iPhone Unity internal profiler stats:
cpu-player> min: 15.7 max: 37.2 avg: 24.7
cpu-ogles-drv> min: 3.4 max: 9.1 avg: 4.8
cpu-waits-gpu> min: 0.3 max: 3.8 avg: 0.4
msaa-resolve> min: 0.0 max: 0.0 avg: 0.0
cpu-present> min: 0.8 max: 3.1 avg: 1.5
frametime> min: 32.0 max: 47.8 avg: 37.2
draw-call #> min: 43 max: 43 avg: 43 | batched: 0
tris #> min: 5496 max: 5524 avg: 5508 | batched: 0
verts #> min: 3878 max: 3934 avg: 3903 | batched: 0
player-detail> physx: 1.0 animation: 0.9 culling 0.0 skinning: 1.0 batching: 0.0 render: 16.5 fixed-update-count: 1 … 3
mono-scripts> update: 0.4 fixedUpdate: 1.9 coroutines: 0.0
mono-memory> used heap: 454656 allocated heap: 643072 max number of collections: 0 collection total duration: 0.0