Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iOS9, Unity5.2, Extreme Random Spikes in Profiler

Discussion in 'iOS and tvOS' started by fraoula, Oct 18, 2015.

  1. fraoula

    fraoula

    Joined:
    Mar 25, 2015
    Posts:
    14
    Hello,

    We're struggling with an issue. Our game is a fast paced 3D arcade game. When built for iOS, we're experiencing some major hiccups which pause the game for about half a second or even more. That ultimately causes player-death and GameOver because the game is so fast-paced and difficult.

    Here's some info:
    - it happens about 2-5 minutes into the gameplay (one level lasts about 2 minutes only)
    - it can happen again after loading another level or in the same level
    - it doesn't happen in a specific location/time in the level, it's random
    - it happens only on iOS devices, we've tried android and playing in the editor, all goes smooth
    - it's driving us crazy! :D

    Unity version: 5.2.1f1
    Xcode 7.0.1
    iOS 9.0.2
    Device: iPhone6 (it happens on other iOS devices from iPhone4 onwards but the profiler screenshots are for iPhone6)

    Naturally, we profiled the spikes, thinking it would help, but then it got really weird.

    First time we caught it, it was - batch draw dynamic -. We really don't use much dynamic batching, it only saves us 4 draw calls in the profiled level. here's the screenshot:



    Then, we tried again and this time it was static. Note the hugeness of the spike. Please ignore the violet spike that comes afterwards, that's the player-death, game-over which triggers loading another scene.



    Then it was physics :D



    Then we tried turning off the dynamic batching and turning off "Optimize Mesh" in import settings of our FBXs. The spike was a bit smaller this time but it didn't help much.




    Can anyone help us here? Did anyone see anything like this before.

    It's insane that the game runs so much better than 60fps and then BAM! a huge spike like that.

    Again, this doesn't happen on Android(way weaker than iPhone6) or in Editor.
     
  2. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    938
    It's most probably the Garbage Collector in action... Although, it's very weird it's not happening on Android.
     
  3. fraoula

    fraoula

    Joined:
    Mar 25, 2015
    Posts:
    14
    The garbage allocation seen in the profiler pics is from a FPS_Display script and some Time_trail script. We've made a new build without any of those. The GC Allocation is at constant zero, but the issue persists. Also, the profiler pics above are from an iPhone6 and we've tested on an old Android phone that's more than 3 years old, no issues at all. So I doubt it's a GC issue :| Might there be some garbage not reported in the profiler?
     
  4. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    938
    From my experience, occasional stuttering is invariably caused by the GC... However, with what you describe your case is indeed weird. I'd recommend you to submit a bug report and include the project (or a part of it that replicates the issue).
     
  5. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    On our project, there are three things that commonly causes "random" spikes in iOS: the Garbage Collector (which is slow regardless of how fast the device is), Unity pausing to compile a new shader the first time it is sent to the GPU, and loading a file from Resources the first time. The reason people keep returning to the GC is because the GC in the profiler always just causes a different piece of code to show up as taking a long time, which is what you are describing.
     
  6. fraoula

    fraoula

    Joined:
    Mar 25, 2015
    Posts:
    14
    Is it possible that the GC causes problems on iOS only and not on android? On android, the largest spike we've ever seen is 60ms. On iOS about 500ms on a much faster device. Also, is it possible that GC causes problems even if the garbage allocation in the profiler is at constant zero and if we don't see any variations in the memory consumption in the memory graph in profiler?

    Regarding the shader/resources load. The spikes happen randomly, not at the same time/place in the level. All the resources are loaded before the level starts. The objects are all pooled and prepooled on level start. We never call Destroy() mid game.

    Today, we've run some automated tests for hours, when the game plays the level (with various stuff enabled or disabled) over and over again. We log the spikes as they happen. The results didn't help at all. Sometimes we have 3 spikes in 10 minutes and sometimes the whole hour passes without any spikes. Crazy.
     
    Last edited: Oct 20, 2015
  7. etig

    etig

    Joined:
    Feb 15, 2015
    Posts:
    11
    Hi,
    Did you solved it?
     
  8. fraoula

    fraoula

    Joined:
    Mar 25, 2015
    Posts:
    14
    Yes, we solved it. Forgot to update this thread. We first reverted back to Unity 5.1. and the spikes were rarer and smaller (around 90ms). Then we tried the new Unity 5.2.2. and disabled Metal. The spikes disappeared. So I suppose it was a problem with some of our shaders when using Metal.