Poor performance with 1st Generation iPhone

I am trying to get my current game working well on all iOS devices and it does work well on iPad and on my iPhone 4 but on a 1st gen iPhone the performance is pretty terrible.

My current scene has around 2-4k tris and 4-6k verts at any given time and by using the CombineChildren script I have gotten my draw calls to below 25, even as low as 15. However my frame is pretty bad, averaging around 12-15 fps at any given time. The scene is really simple, with only 1 directional light, only 1 actual texture being used, and all shaders are set to ‘Diffuse Fast’. I don’t think my scripts in my game should really be causing the frame rate to drop so drastically, so is there anything else that I can do to improve performance on 1st Gen iPhones?

Below is the statistics from the editor in the exact same state as my iPhone game, but the iPhone game at this point is only rendering at 12 fps.

488592--17156--$Screen shot 2011-02-01 at 8.58.18 PM.png

you have quite a few verts, if they are animated or widely animated thats basically bad to very bad.
Drawcalls and tris otherwise are at / below border and should allow you to get 20 FPS more or less.

to find out what really is the problem, use the in application profiler you enable through the define in AppController.mm and run it on the device to see whats really eating the time

to be fair though I would just ignore it and don’t waste time.
The first generation devices (iphone + itouch) together are below 0.5% of the install base.

iphone 3G and especially 2nd gen itouch are much more important (they together are in the line of 20-25% install base and thus justify time investment given you want to support ARMV6 - pre 3GS hardware at all - the gap between these 2 ie 2nd gen and 3GS gen is massive, 100%++ depending on what you do)

Dreamora, thanks for the profiler tip, I had no idea that existed.

So after running the game with the profiler running here are my results:

Profiler At 24 fps (only local player)

iPhone Unity internal profiler stats:
cpu-player> min: 25.4 max: 42.4 avg: 31.5
cpu-ogles-drv> min: 2.4 max: 9.9 avg: 5.0
cpu-waits-gpu> min: 0.0 max: 0.1 avg: 0.0
cpu-present> min: 1.4 max: 3.7 avg: 1.8
frametime> min: 37.5 max: 51.5 avg: 41.4
draw-call #> min: 10 max: 10 avg: 10 | batched: 11
tris #> min: 7030 max: 7030 avg: 7030 | batched: 22
verts #> min: 4424 max: 4424 avg: 4424 | batched: 44
player-detail> physx: 5.4 animation: 1.1 culling 0.0 skinning: 1.1 batching: 0.2 render: 14.6 fixed-update-count: 2 … 3
mono-scripts> update: 7.0 fixedUpdate: 0.2 coroutines: 0.3
mono-memory> used heap: 4448256 allocated heap: 6746112 max number of collections: 0 collection total duration: 0.0

Profiler At 15fps Average (added second network player)

iPhone Unity internal profiler stats:
cpu-player> min: 38.1 max: 64.4 avg: 49.5
cpu-ogles-drv> min: 2.5 max: 9.3 avg: 4.3
cpu-waits-gpu> min: 0.0 max: 0.1 avg: 0.0
cpu-present> min: 1.5 max: 3.9 avg: 2.2
frametime> min: 48.2 max: 82.9 avg: 63.4
draw-call #> min: 12 max: 12 avg: 12 | batched: 11
tris #> min: 7090 max: 7090 avg: 7090 | batched: 22
verts #> min: 4560 max: 4560 avg: 4560 | batched: 44
player-detail> physx: 5.9 animation: 0.8 culling 0.0 skinning: 1.1 batching: 0.1 render: 17.6 fixed-update-count: 2 … 4
mono-scripts> update: 12.7 fixedUpdate: 0.3 coroutines: 0.3
mono-memory> used heap: 5222400 allocated heap: 6746112 max number of collections: 0 collection total duration: 0.0

Correct me if I am wrong but it actually looks as though my scripts are too taxing on the CPU, as when I was getting 24 fps my render time was 14.6 but when I was getting 15 fps my render time was 17.6, so scripts must be accounting for the large fps loss.

You have a lot Update calls in there, definitely (12.7 seconds)
If I would have to guess I would guess you use GetComponent / FindObjectOfType / Find in there or loop over larger amounts of objects, which is bad as its taxing. Where possible you should do it in start and store the reference for later usage.

The draw calls are easy but you have something in rendering thats pretty taxing (you have a 3s delta on the render time for the frame which is quite a bit, thats nearly 20%) and yes your update spikes up quite far by over 80%

What physics time step do you have configured? I assume something smaler than 0.032 (30 FPS)? Physics 6ms is quite high and with just 1 player the game would need to be really complex to allow that (don’t use mesh colliders unless really needed like a terrain replacement mesh, don’t use complex physics systems unless your game is only about physics, …)

Also if networking is the target forget the 2G completely. it has no wifi and 2G is as useless as it can be for networking (you will get latencies in the horror range all the time and the bandwidth is small enough to be a problem on its own)

I know now that I really need to go through and optimize my update loops in a bunch of places, as I am sure I have left some GetComponents and possibly some finds in them. I also notice that there is a huge spike in CPU time when you shoot which I realize is because I instantiate a new bullet tracer prefab each shot, and some guns shoot up to almost 15 times a second.

Also when you say that the 2G doesnt support wifi, are you talking about the 1st Gen iphone or ipod touch, but either way , all models of ipods and iphones have supported wifi. I am definitely considering just not supporting pre-3Gs devices but I haven’t been able to find solid statistics on device install base percentages. Do you possibly have a link to the article where it gives these numbers that you are referring to in your first post?

Anyways thanks for the help, I am now looking in the right places that I need to optimize!

I’m talking about the first generation iphone. The 1st gen iPod Touch did have wifi, but I thought the iPhone 2G didn’t have (wasn’t released in europe, so I have to go with what I read on its limitations in its days when I started iOS development with the 1st Gen itouch)

The links I have aren’t up to date unhappily. The last I had was with a 55% share of the 2nd gen devices in Q1 2010 due to the itouch 2nd gen being sold as “8GB itouch 3rd gen” along the real 3rd gen
With each new iphone generation selling even better than the previous one up so far, its to expect that this by now dropped below the 30% range actually.