Performance issue with 3GS

Hey, I’m having a problem with performance on an iPhone 3gs compared to ipod touch 4g. The 3gs is running considerably slower, according to the timings almost half the speed. I’ve hunted around for information about why this might be but I can’t find anything that helps, everyone else seems to have problems the other way round.

I’m using procedural animation (flocking) so was always going to be fairly heavy on the cpu, but I just don’t understand the speed difference between these devices. I was expecting fairly similar performance as they both have the same processor (albeit at different speeds).

I’ve fiddled with all the settings I can find in Unity and xcode, but there is always a big difference. Can anyone think of any reasons this might be? Or is this just the normal difference between these devices?

These are the outputs from the internal profiler, both are from exactly the same build, and I don’t have any code that detects, or works differently on different devices.

ipod 4g
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  3.6   max:  7.0   avg:  5.6
cpu-ogles-drv> min:  0.5   max:  1.6   avg:  0.7
frametime>     min: 14.1   max: 19.7   avg: 16.6
draw-call #>   min:   4    max:   4    avg:   4     | batched:    25
tris #>        min:  1292  max:  1292  avg:  1292   | batched:  2392
verts #>       min:  1046  max:  1046  avg:  1046   | batched:   875
player-detail> physx:  1.0 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  0.8 fixed-update-count: 0 .. 1
mono-scripts>  update:  2.8   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 380928 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

3gs
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  9.1   max: 22.5   avg: 13.8
cpu-ogles-drv> min:  0.7   max:  5.2   avg:  1.6
frametime>     min: 17.2   max: 54.2   avg: 26.1
draw-call #>   min:   3    max:   4    avg:   3     | batched:    27
tris #>        min:  1149  max:  1538  avg:  1367   | batched:  2686
verts #>       min:   923  max:  1259  avg:  1102   | batched:  1008
player-detail> physx:  4.5 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.4 render:  0.5 fixed-update-count: 0 .. 4
mono-scripts>  update:  6.1   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 376832 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

Thanks a lot!

But you just said it, right? They may have the same processor, but they run at different speeds (600 / 800 Ghz). With a CPU intensive process like boids that’s quite important, isn’t it?

Heh, I often find it harder to get stuff to run nice on 4G due to the larger amount of pixels.

Basically you have to optimize your code, not sure how much you have done towards this but here are some suggestions:

  • do stuff in coroutines not in update
  • avoid using new wherever possible (cache instead)
  • avoid using built in component identifiers (instead cache a local reference to them)
  • make sure you aren’t destroying/instantiating

You might then need to look at the algorithm itself:

  • can you get the same result with a cheaper operation?
  • can you pre-calculate anything?
  • can you use a heuristic or estimation in place of a (heavy) exact calculation?

If you post some code might be easier to address specifically :wink:

Thanks for the replies,

I’ve definitely got more optimizations I can do with the code as I’m still fairly early on in development, but at this stage I was really shocked at the difference in speeds, I just wasn’t expecting it to this degree.

The clock speed difference is 33%, but I’m seeing a more than 100% increase in performance according to the profiler timings.

mixed up a thing

How many boids do you have in your simulation? I did this a few days ago… I should try it on my old iPod 2nd Gen.

@dreamora - they are both the same cpu generation, an arm cortex a8, just running at different speeds. All the benchmarks I can find suggest an increase of around 35% cpu performance.
http://www.primatelabs.ca/blog/2011/10/iphone4s-benchmarks/
http://www.anandtech.com/show/3794/the-iphone-4-review/12

I’ve only got 16 boids at the moment, although I do have a game running too :slight_smile:

change above / cut it.

well there is one thing that we didn’t ask so far: did you ensure both devices are on the same degree of usage? itouches tend to be not as heavily used as iphones in consequence they have more to much more ram at hand which could force the 3GS iOS to resort cpu time to manage it more actively to give you the needed ram and vram. to verify that reboot both and check again

One thing you surely should consider is dynamic scaling code, changing the cpu time for physics for example (unless it runs on 30 FPS / 0.033 anyway)

Well after a load of mucking about stripping out code trying to find what was going on I think I’ve discovered it! Blooming IOS5! There seems to be something killing performance on a 3gs with ios5. I don’t know what other devices are affected, I’ve only got an ipad2 with ios5 and it doesn’t seem to make any difference on that, but could be due to how much more powerful it is.

I’ve tried running the geekbench app on all the devices and they come out as expected, no variance based on IOS version, so it would seem that this is something broken in Unity.

I’ve attached all my results from the profiler below; the difference between the ‘no touch’ and ‘touch’ result is the game is running idle during ‘not touch’, and during ‘touch’ I’m sliding my finger about and the game is updating and moving stuff about.

3gs ios4.3.5
no touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  1.9   max:  7.8   avg:  2.6
cpu-ogles-drv> min:  0.2   max:  1.5   avg:  0.3
frametime>     min: 13.2   max: 20.9   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.3 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  0.5 fixed-update-count: 0 .. 1
mono-scripts>  update:  0.9   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 389120 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  1.9   max:  6.5   avg:  2.9
cpu-ogles-drv> min:  0.2   max:  1.7   avg:  0.3
frametime>     min: 10.9   max: 21.8   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.3 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render:  0.4 fixed-update-count: 0 .. 1
mono-scripts>  update:  1.1   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 401408 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------




3gs ios5.0
no touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  2.0   max: 12.6   avg:  4.2
cpu-ogles-drv> min:  0.3   max:  5.3   avg:  0.8
frametime>     min: 10.1   max: 27.0   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.3 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  0.8 fixed-update-count: 0 .. 1
mono-scripts>  update:  1.1   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 335872 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  2.1   max: 27.0   avg:  6.7
cpu-ogles-drv> min:  0.3   max:  7.6   avg:  0.9
frametime>     min:  7.2   max: 37.9   avg: 16.9
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.5 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  1.3 fixed-update-count: 0 .. 1
mono-scripts>  update:  2.4   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 405504 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------




3gs ios5.0.1
no touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  2.0   max: 12.2   avg:  4.1
cpu-ogles-drv> min:  0.3   max:  3.6   avg:  0.7
frametime>     min: 10.3   max: 27.7   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.3 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  0.7 fixed-update-count: 0 .. 1
mono-scripts>  update:  1.1   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 425984 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  2.1   max: 14.5   avg:  5.9
cpu-ogles-drv> min:  0.3   max:  6.9   avg:  0.9
frametime>     min:  9.5   max: 30.3   avg: 16.8
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.4 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.1 render:  1.5 fixed-update-count: 0 .. 1
mono-scripts>  update:  2.0   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 348160 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------





iPod touch 4g iOS 4.3.2
no touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  1.2   max:  3.9   avg:  1.7
cpu-ogles-drv> min:  0.2   max:  1.2   avg:  0.2
frametime>     min: 14.2   max: 20.1   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.2 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render:  0.2 fixed-update-count: 0 .. 1
mono-scripts>  update:  0.6   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 393216 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  1.4   max:  5.0   avg:  2.0
cpu-ogles-drv> min:  0.2   max:  2.5   avg:  0.2
frametime>     min: 13.0   max: 20.3   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.2 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render:  0.3 fixed-update-count: 0 .. 1
mono-scripts>  update:  0.7   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 327680 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------



ipad 2 ios5.0
no touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  0.7   max:  7.6   avg:  1.3
cpu-ogles-drv> min:  0.1   max:  0.6   avg:  0.2
frametime>     min: 10.1   max: 23.1   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.1 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render: -0.3 fixed-update-count: 0 .. 1
mono-scripts>  update:  0.4   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 405504 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

touch
----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  0.8   max:  8.0   avg:  1.6
cpu-ogles-drv> min:  0.1   max:  0.8   avg:  0.2
frametime>     min: 10.0   max: 23.2   avg: 16.7
draw-call #>   min:   2    max:   2    avg:   2     | batched:     4
tris #>        min:   194  max:   194  avg:   194   | batched:   372
verts #>       min:   136  max:   136  avg:   136   | batched:   132
player-detail> physx:  0.2 animation:  0.0 culling  0.0 skinning:  0.0 batching:  0.0 render: -0.2 fixed-update-count: 0 .. 1
mono-scripts>  update:  0.5   fixedUpdate:  0.0 coroutines:  0.0 
mono-memory>   used heap: 331776 allocated heap: 479232  max number of collections: 0 collection total duration:  0.0
----------------------------------------

I also tried benchmarking a totally empty scene, and there is still a noticeable slowdown with the 3gs on ios5.