Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

iOS8 on iPhone6 framerate running at 20FPS! (WTH)

Discussion in 'iOS and tvOS' started by WhosTheBoss, Nov 1, 2014.

  1. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    I'm testing my new game. It is a 3D zombie shooter.

    On Unity Editor i get >100FPS.

    On my iPhone4S (iOS7) i set it to 30FPS and i'm getting roughly 30FPS.

    On my iPhone5S(iOS7) i set it to 60FPS and i'm getting roughly 57-60FPS.

    On my iPhone6(iOS8) i set it to 60FPS but the frame rate is dropping down to 20FPS. The Menus run at a smooth 60FPS. When i start playing the game i'm get 60FPS but all of a sudden it drops all the way to 20FPS and struggles between 20-33FPS.

    I really don't know WTH is going on. It looks like it's an iOS8 issue.

    Is there anyone else having this sort of issue?
     
  2. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Thanks for the feedback, but I really think you should try it with profiler attached to see exactly what is causing the issue as currently no one can tell what the problem is. We know there is bad performance when it comes to new software as I'm sure Unity 5 beta has many fixes..
     
  3. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Resolution on the iPhone 6 is larger. Therefore any performance gains from the 5s to the 6 will be lost. Case in point with the 6 plus...

    "Earlier, AppleInsider noted that Apple's own leap to a Retina HD 1080p screen on iPhone 6 Plus resulted in graphics that were in some cases slower at their native resolution than last year's iPhone 5s: rendering a challenging OpenGL ES 3.0 3D scene dropped frame rates from 24.4 to 19 fps."

    http://appleinsider.com/articles/14...r-graphics-performance-vs-apple-iphone-6-plus

    While your code or even unity might still have performance issues when dealing in specific areas of multiple threads being handled within iOS 8, I believe the biggest hit is coming from the increase in resolution and additional patches needed for iOS 8. Just my two cents.
     
  4. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Thanks for both of your replies. Too bad i have Unity free so i can't use profiler.
     
  5. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Maybe 30 Day Pro Trial..
     
  6. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    WhosTheBoss,

    It's just too hard to say without completely understand everything you might be trying to do and how you might be attempting to do it.
     
  7. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    New_guy,

    The game is for iOS only. The concept of the game is simple, the main character just shoots zombies.

    Now, in my splash screen, i detect which iOS device by looking at iPhone.Generation, if it's older devices (iPhone4,4s, iPod 3rd generation, iPad3 etc) i set the Application.TargetFreamRate to 30 and i set the MAX_ZOMBIE_COUNT to 10 so only 10 zombies can be spawned at a time.

    However, if the game is running on newer devices (iPhone5,5s,6, 6+, iPad 5th gen etc) i set the the framerate to 60 and max_zombie_count to 28.

    I build the project, load up Xcode6, I have all kinds of iPhones and iPads in my house. i build the game into all my iOS devices and all of them run perfectly as coded.

    The older devices(iOS6 to iOS7) run at 30FPS and plays very smooth at 30FPS with 10 zombies attacking the player.

    The newer devices(iOS7) run at 60FPS and plays very smooth at 60FPS (57-60FPS) with 28 zombies attacking me.
    But, on the my iPhone6(iOS8), it starts of at 60FPS then as i'm playing the game it drops to 20FPS, at times it is at 18FPS which is totally unplayable!

    It is really annoying me, some times i'll play it on my iPhone6 and it plays at 60FPS no problem but other times it will drop down to 20FPS.

    I really don't get it! How can an older iPhone5 and 5s run at 60FPS with 28 zombies BUT a newer more powerful iPhone6 struggles with low framerates with the same 28zombies on screen.

    I think the folks at Apple sacrificed some CPU/GPU performance for better battery on iOS8. Which is probably why they launched the Metal API.
     
  8. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Yea, i'm gonna try the 30-day pro
     
  9. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Is vsync set to true in quality setting?
     
  10. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    You should start looking into Xcode debugger navigator, here on FPS tab you will how much time spent on CPU vs GPU. This will give you insights if you are CPU or GPU bound.
     
  11. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Mantas,

    looking there, the CPU is really bugged out, looks like the CPU is very busy calculating something, the process delay times are exceeding 30ms ( i think, i cant remember the exact times. I'll check when i get home)

    But i do remember that when ever the frame rate drops, the CPU processing time increases.
     
  12. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Too bad you haven't noticed that Unity free has a built-in (non-graphical) profiler.
     
  13. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Here's a screenshot.

    Graham,
    are you referring to the Statistics window in the Game view?

    As you can see in the screen shot i attached. The CPU is damn near 40ms in rendering a frame. This is on my iPhone6.

    But, On my iPhone5 and 5S, the CPU time barely reaches double digits and the iPhone5/s are always at 60FPS.
     

    Attached Files:

  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    looks like cpu is taking up most of the time. That's unusual. Also, why is it showing that data in the console when it should be showing allocations etc? did you toggle it on?
     
  15. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    What is being wrote to disk just before the drop?
     
  16. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    My Xcode console has always shown that, i did not know you can change the contents you want it to display. Yes! it's very unusual for the CPU to be performing so much task. I'm completely lost in what to do.


    New_To_Unity_Guy,
    I'm not sure what was loaded, i'll do more tests to figure out what was read/write from disk.
     
  17. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    1) Are you loading a new scene without removing the old from the stack?
    2) Are you making use of Prefabs?
    3) How many scripts are you using?
    4) OR did you split them up to specific game objects?
    5) Have you changed the delta time?
    6) Are you using Fixed Update OR Update?


    Also, click on your CPU tab to check how many threads are running.
     
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  19. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    I'm not sure what was read/written to disk but i've sat here and watched it, there were other read/writes to the disk and there was no drop. Moreover, it has also dropped when there was no read/write to disk at all.

    So the read/write is not the cause.
     
  20. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    unfortunately, i had a busy day so i didn't get a chance to do more analyzing. I will try what everyone has suggested.

    BUT......................

    One thing to keep in mind is this: Let's just say my memory management skills are poor, Now why in the glory heck is an old 2012 iPhone5 technology staying at 60FPS (same game, same script, same binary, same build, same amount of characters on screen)
    But a 2014 more powerful iPhone6 is barely pushing out 25FPS?

    My gut instincts are telling me that is has to do with how iOS8 runs on iPhone6.
     
  21. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Display Resolution has a direct impact on GPU performance. As far as why, I can only assume that your code that switches from one quality settings to another is buggy. Maybe fix the quality settings to one set and then see how things stack up.
     
  22. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    New_To_Unity_Guy, sure. Thanks, i'll try that ASAP.

    But here's how i set the devices:

    switch(iPhone.Generation)
    {
    case iPhoneGeneration.iPad3Gen:
    case iPhoneGeneration.iPhone4:
    case iPhoneGeneration.iPhone4S:
    case iPhoneGeneration.iPodTouch4Gen:
    case iPhoneGeneration.iPodTouch5Gen:
    Application.targetFrameRate = 30;
    GlobalVariableScript.ON_SCREEN_ENEMY_MAX = 10;
    break;​


    case iPhoneGeneration.iPad4Gen:
    case iPhoneGeneration.iPhone5:
    case iPhoneGeneration.iPhone5C:
    case iPhoneGeneration.iPhone5S:
    case iPhoneGeneration.iPhone6:
    case iPhoneGeneration.iPhone6Plus:
    Application.targetFrameRate = 60;
    GlobalVariableScript.ON_SCREEN_ENEMY_MAX = 28;
    break;​

    default:
    //...
    break;​
    }

    That is it!!!!!!!!! I'm not doing anything else.

    If it were a resolution thing, then how come the iPhone6 sometimes will play at 60FPS for 2-3 or even 4 minutes then all of a sudden at random times falls to 24FPS and stays there. The LCD on the iPhone6 didn't all of a sudden get larger.

    I really thank all of you guys for chiming in... I'll continue to dig this problem.

    I also noticed, when the iPhone6 slows down, i paused the game locked my iPhone6. I let it sit for about 5mins. Then when i go back to it, it resumes at 60FPS.

    Again, it is sounding like Apple is slowing the CPU down when it detects that a particular app is sucking up a lot of battery. It may sound crazy and if it does please correct me. But one of the so called "features" that iOS8 has is that it is great in conserving battery. (Which comes at the cost of performance)

    Also, i said that because this is not the first time such a thing has happened. Late last year, when i was testing my game on my iPhone4s with iOS6.X, my game ran great at 30FPS no problem. Then when iOS7 was launched my game started crawling at 19-22FPS. I didn't know what the heck was going on, i almost gave up. Then Apple released iOS7.1 and all of a sudden my game started running at 30FPS with no hiccups. I didn't change a single line of code.
     
  23. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    That is very interesting concerning the 7.1 update. While reading the Application.targetFrameRate documentation, I see that it states it does not guarantee it will. I would try to use one setting without changing it, and make any adjustment with the Quality Manager

    http://docs.unity3d.com/Manual/class-QualitySettings.html

    v sync being the biggest cpu hog needs to be turned off.

    Otherwise, compare draw calls with batching totals. You can do this in unity by running in editor and opening stats in game view. I usually can get around 600 draw calls before dropping FPS on an old iPod5. Obviously, on a Mac, you will be able to go much higher, but finding out where draw calls are being produced will only help with creating a baseline.

    Also, I have noticed at times, that when a device is connected to Xcode to run stats, it seems to slow it down in some areas.

    I'm not saying iOS isn't reducing power or somehow slowing your app down, but at the same time, eliminating any possible source of your own, will only improve on what you have, just saying.

    Good Luck
     
  24. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    I'm one step closer in proving that this is an iOS8 fault.

    I turned off v-sync, no results. Still suffering poor frame rate.

    However, while i was watching the frame rate meter on Xcode, i tried to adjust the volume on my iPhone6 and the frame rate went even lower, all the way down to 13-14FPS and CPU processing time reached 60ms!!! (damn!)

    This is probably so because the iPhone6 is rendering the volume adjustment popup-window. As soon as the volume popup-window disappears, the frame rate returns to 22FPS. I tried it several times and each time the volume popup-window appears, the frame rate went to the teens, when the popup-window disappears, the frame rate is back up.

    Furthermore, i also noticed, each time a notification shows up on top of my iPhone6 (text message, reminder, etc) The frame rate also went down.

    It's like the iPhone is having a hard time rending my game and any other on-screen iOS native window.
     
  25. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Wouldn't vsync actually extend battery life?
     
  26. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    That's what i thought.

    New discovery.
    In Xcode, i'm looking at the CPU window. I noticed that thread 14 becomes busy when the frame rate drops. Whenever thread 14 is idle, the frame rate returns to 60FPS. Does anyone have an idea what Thread 14 is responsible for?
     

    Attached Files:

  27. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Here's a screenshot of the profiler.
     

    Attached Files:

  28. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    If the following is true, then it has to be something specific to iPhone 6.

    In Unity, Project - Player Setting - other settings

    --Config...
    Taget Device = iPhone only
    target resolution = Native
    graphics = Auto


    --Optimization...
    Api Compatibility Level = .NET2.0 Subet
    SDK = device
    Target iOS = 6.0
    Script Call = slow and safe

    ... other thoughts....
    Also notice you have no Fixed Updates running. Are you using (ANY) Time.deltatime in Update?

    Are you using any Find by name or tag in any script?
     
  29. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    In this current game scene i'm not using Time.deltatime. I'm moving my character controllers with .Move().

    Here's a screenshot of my Player settings
     

    Attached Files:

  30. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Are you using GameObject.Find at any point? Say for example to locate the player so that enemies move to that position?
     
  31. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    Yes! Each zombie that spawns, i'll use GameObject.Find to locate the main character and move that direction to attack the main character.

    TargetToAttack = GameObject.FindWithTag("Player").transform;

    By the way, i changed my Player settings to your recommendations and it's still suffering.
     
  32. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes, you'll probably want to read the docs on mobile best practises and do a bit of a search. Get component and .Find are very slow indeed.

    Just store a reference to the player script somewhere and access it directly from the zombies.
     
  33. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Definitely do NOT want to use GameObject.Find in this manner.

    Instead, in the player object script include a global vector3 player Position that updates the vector3 of the player game object rigid body position. Then instead of searching the stack every Update cycle X number of zombies for a tag, you will just update from the global player position.
     
  34. WhosTheBoss

    WhosTheBoss

    Joined:
    Jan 8, 2013
    Posts:
    64
    I FOUND THE PROBLEM!

    It turns out that the iAd was killing my game. It was busy fetching for ads which crippled the CPU.
    In iOS8, Settings > Developer, there are iAd settings, where you can adjust how frequent new ads are fetched and refreshed. (see the attached screenshot)

    - Ad Refresh Rate: doesn't seem to have any effect no matter what i set it to.

    - Fill Rate: made the most impact. When set to:
    0% - Always Error: The game plays ridiculously smooth. Stayed at 60FPS no matter what.
    20%: The game played smooth here as well, always at 60FPS.
    50%: Sometimes ill get 60FPS, other times i'll get poor frame rates.
    80%: Poor frame rates almost always.
    100%: i didn't even do a lot of tests at 100% but all the tests i did were all poor.
    Now with that being said, i only display ads on my menus, there are no ads during game play. However, i've noticed that during game play the ad banner will popup which is a big no-no because it blocks crucial HUD information.

    When the game starts, i try to disable ads by:
    void Start ()
    {
    // Remove ads
    AdBanner.visible = false;​
    }
    But that only removes it briefly, every now and then, the banner will show up again and block HUD information.


    So to make sure that the banner never shows up during game play, i did this:
    void Update()
    {
    if(AdBanner.visible)
    {
    // Do not show Ads during gameplay.
    AdBanner.visible = false;​
    }​
    }
    I'm not sure if doing this will be expensive on the CPU.

    Does anyone know?
    What is the best way to disable the banner during gameplay?

    Thank you all for all your help, i greatly appreciate it.

     

    Attached Files:

  35. New_To_Unity_Guy

    New_To_Unity_Guy

    Joined:
    May 30, 2014
    Posts:
    31
    Wow, that is great news! I have not even looked at iAd yet. However, I am very interested to see the solution.