iOS performance problem (iphone 4 on iOS6)

Dear all

I have a problem with the iOS performance of a simple 2D game.

Normally, it runs very smoothly showing stat A. Occasionally, I notice during collision detection, there is a noticeable delay .

I have tried to move a lot of the codes away from Update(), and put the codes in coroutine. this did improve the performance slightly but still the delay persists. Then I changed all my colliders from 3D to 2D. Also I replaced the default onTriggerEnter/Exit/Stay with custom-made functions using raycasting to detect trigger events.

Still I have a delay problem every now and then (see stat B)

Any clue how I could address this problem? thanks a lot for your help!

A

----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  3.8   max: 12.0   avg:  7.2
cpu-ogles-drv> min:  0.5   max:  2.6   avg:  0.9
cpu-present>   min:  0.8   max: 162.9   avg:  6.8
cpu-waits-gpu> min:  0.8   max: 162.9   avg:  6.8
 msaa-resolve> min:  0.0   max:  0.0   avg:  0.0
frametime>     min: 12.2   max: 193.5   avg: 37.1
draw-call #>   min:   7    max:   7    avg:   7     | batched:     2
tris #>        min:   314  max:   314  avg:   314   | batched:     4
verts #>       min:   628  max:   628  avg:   628   | batched:     8
player-detail> physx:  0.7 animation:  0.3 culling  0.0 skinning:  0.0 batching:  0.2 render:  3.5 fixed-update-count: 1 .. 9
mono-scripts>  update:  2.4   fixedUpdate:  0.0 coroutines:  0.2 
mono-memory>   used heap: 585728 allocated heap: 786432  max number of collections: 0 collection total duration:  0.0

B

----------------------------------------
iPhone Unity internal profiler stats:
cpu-player>    min:  3.0   max: 436.8   avg: 20.9
cpu-ogles-drv> min:  0.5   max:  3.5   avg:  1.1
cpu-present>   min:  0.8   max:  6.0   avg:  1.9
frametime>     min: 22.4   max: 470.1   avg: 46.9
draw-call #>   min:   8    max:  10    avg:   8     | batched:     2
tris #>        min:   218  max:   228  avg:   224   | batched:     4
verts #>       min:   436  max:   448  avg:   442   | batched:     8
player-detail> physx:  0.9 animation:  0.1 culling  0.0 skinning:  0.0 batching:  0.1 render:  3.2 fixed-update-count: 1 .. 17
mono-scripts>  update:  1.6   fixedUpdate:  0.2 coroutines: 14.5 
mono-memory>   used heap: 618496 allocated heap: 786432  max number of collections: 0 collection total duration:  0.0

“Delay problems” usually points at the Garbage Collector. If you are using Unity Pro (I forgot if you need pro for that info) you can use the Profiler to look at the GC allocations which will eventually add up to the point the GC kicks in and kicks your performance in the balls for a frame.

If Unity Free… Ummm… You’re stuck checking the code yourself :confused:

Basically, try not to allocate “new” objects every frame. Pretty much any time you use the “new” keyword with a class (as opposed to a struct), you’re asking for GC-managed memory and when it runs out it checks which objects don’t have references and frees the memory for reuse which is rather slow.