Search Unity

  1. Tune in to get all the latest Unity news live from Berlin on June 19, 6pm CEST. Set up a YouTube reminder!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Performance problems switching back to app iPhoneX

Discussion in 'iOS and tvOS' started by Johannski, Jun 12, 2018.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Quick summary of the thread (15.06.2018)
    On the iPhoneX I'm getting stuttering in about 80% of the time when switching to the homescreen and then back to the app (Profiler says Gfx.WaitForPresent). Stuttering is not happening when screenrecording, also not happening for @PixelEnvision.

    Variations tested

    - Tested with Unity 5.5.5p2, Unity 5.6.3p3 and Unity 2018.1.4f1 and XCode 9.4 (Local Build)
    - Tested with Unity 2017.4.5f1 and Unity 2018.1.4f1 and XCode 9.3 (Cloud Build)
    - Used different machines, cables and USB ports for profiling
    - Factory Reset of the iPhoneX with fresh Apple Account
    - Running the Phone in Airplane Mode
    - Running other Apps (like Alto's Odyssey) made with Unity on that iPhone X do not show such problems
    - Release Build has stuttering as well, seen way better with larger app, but also slightly visible with the simple rotating rings app
    - Does not happen for iPhone SE, iPhone 6s, iPhone 6s Plus and iPad Pro

    Useful Links

    - Github Repo
    - Stutter Recording iPhone X with Unity 2017.4.5f1
    - Post starting with the general test

    What I need

    - One or two more tests from others with an iPhoneX (e.g. by creating a quick cloudbuild with linking to the repo)
    - Ideas what else to test, since I'm running out of ideas





    Original Post
    Hey there,

    I fighting with a very strange bug for a few weeks now and it really destroys me that I can't find any possible source for the problem. I really hope someone out there has any idea where the problem might come from. So here it comes:

    When I start the app, everything works as expected, but when I switch to the home screen and then back to the app, suddenly the app starts stuttering. The stuttering is about 3 seconds long if I do nothing, but when I switch back and forth in the menus I can hold the stuttering for almost as long as I want. Once the stuttering is gone, everything is back to normal and the app works as expected again. This happens only on the iPhoneX. Strangely enough I recently thought I got rid of the problem, since I had a build where the problem didn't occur. Also the next build had no problems, but the build of today had the problems again. When going back to the old builds through testflight, the old builds that had no problems suddenly also showed the same problems. The builds are exactly the same since they are stored on testflight. I use the iPhoneX also as my personal phone, but didn't do anything unusual lately with it.
    I tried restarting the phone, Airplane Mode, Disabling GameCenter, but sadly those didn't solve the problem.
    Specs about the project:
    - Unity 5.6.3p3
    - XCode 9.4 (9F1027a)
    - Using GameCenter and Cloud Save
    - Using Fmod 1.09.04
    - Unity PerformanceReporting
    - Unity Analytics

    This is what the profiler shows:
    Screen Shot 2018-06-12 at 16.45.58.png
    I would be really thankful for any input. I'm working on the project for over 2 years now and it is killing me to see, that it won't run smooth even though I put a lot of time and care into optimizing it.

    Edit:
    I checked if the problem is Unity 5-specific, sadly I get the same behavior in 2018.1.4f1:
    Screen Shot 2018-06-13 at 09.54.24.png
     
    Last edited: Jun 15, 2018 at 11:14 AM
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Update:
    Okay, apprently I was hunting ghosts, that where not connected with any of the plugins, but unity itself. For all my builds this problem happens, even with a very simple test project. Here is the bug report:

    1. What happened

    When deploying on iPhone X this very simple scene with 9 rotating rings starts to stutter when the app is minimized and reopened again. This might be not too visible for this current scene, since it is so simple, but the profiler shows clear spikes and the main game we are working on has way worse spikes, due to this problem.

    The problem does not occur on iPhone 6s, iPhone 6s Plus, iPhone SE and iPad Pro. We believe it is tied to iPhone X. For the larger project I also did a test with Unity 2018.1 and the problem there seems to persist. The problem is also reproducable with Unity 5.5.5p2 (which is the last version I can test with Mac OS 10.13). I did a cloud build with Unity 5.4.2p4 for another project that had the same problem, and there everything seems to run smoothly on the iPhone (but is in the boxed mode).

    2. How we can reproduce it using the example you attached

    1.) Build the project as a development build on an iPhone X.
    2.) Once the profiler is attached and the framerate gets stable, minimize the app
    3.) Reopen the app (you can do that instantly) and take a look at the profiler. You will see some spikes from GFX.WaitForPresent. Those spikes will happen on other devices as well, but not in that magnitude and length. For us it is really killing the performance on iPhoneX for the current app we're developing.

    Tested Affected Versions:
    5.5.5p2
    5.6.5p3
    2018.1.4f1

    Tested not Affected Versions:
    5.4.2p4

    Built with XCode 9.4

    Behavior-iPhoneSE.png
    Behavior-iPhoneX.png

    Very strange that nobody else found that problem so far. I attached my example project, could somebody try to reproduce the problem? :)
     

    Attached Files:

  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    4,642
    I'd love to help, but I don't have an iPhone X.

    But it seems that you have enough to do a pretty great bug report! So I think you should do that.
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Thanks for the support! Yeah, I hope so as well. I already filed it. But I'm still irritated that I saw nobody else filing the bug and that there are apps out there (e.g. Alto's Odyssey), where I can't see any issues. Maybe it is connected to the XCode version... I'm really not sure anymore.

    Another very strange thing I found: When screencapturing is running the stuttering does not show up. I don't know what to get from that...
     
  5. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    439
    Hi,

    I've just tested your project and one of my own. Both seems to work fine, I didn't experience the issue or saw any spikes. On another note, xcode profiler's cpu usage raised about %4 percent after resuming (28 to 32) your test project while that didn't happen on mine. Tested with Xcode 9.4.1 (just updated earlier today) with latest unity LTS 2017.4.5f1 on iPhone X with latest non-beta ios.

    I hope this helps...
     
  6. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Hi PixelEnvision,
    thanks a lot for testing. Hm, I guess then I need to check the LTS version as well. Running 11.4 on my iPhone X as well (I had betas on there as well, but since 11.4 is out of beta I jumped off that train).
    Sadly the mac mini I built on was needed otherwise, but I will try to reproduce the problem with cloud build.

    Thanks a lot for giving it a go, too bad I'm still alone with the problem.
     
  7. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Okay, so I got Cloud Build involved to make sure that my setup on the mac is not the problem.
    The problems do occur on Unity 2017.4.5f1 and 2018.1f4 as well:
    upload_2018-6-14_18-35-44.png
    upload_2018-6-14_18-37-7.png

    I guess the next step is factory reset of the iPhone. I'll keep you posted :)
     
  8. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    2,231
  9. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Thanks for the reminder, already did that. This thread is thought to support the bug report as well as include the community in solving this more transparently. Since I'm fighting for quite some time with this problem I thought it will be relevant to others as well :)

    So here's the current status:
    • I uploaded the repo to github to easily build with cloud build (https://github.com/JohannesDeml/RotatingRingsUnity).
    • I did a factory reset with the phone and started again with a before unused apple id. Then installed testflight and the test app (actually through testflight). When profiling I'm seeing the exact same results (Unity 2017.4.5f1):
      upload_2018-6-15_10-29-53.png
    • Tested with a different cable and USB port (Tested on MacMini before now on a windows computer), problem seems to persist. I should note however that it happens about 80% of the time. In 20% it looks more like this:
      upload_2018-6-15_10-47-8.png
    • As mentioned before, when screencapturing, the problem does not show up at all:
      upload_2018-6-15_10-48-30.png
    • I added a profiler Recording with spikes to the release section of the repo: https://github.com/JohannesDeml/RotatingRingsUnity/releases/tag/iPhoneXSpikesRecording20180615
    So this leaves me wondering once again. From the matter of fact that there are no spikes or only the very little overhead that otherwise happens in 20% of the time when screencapturing gives me three ideas:
    • iOS has CPU Frequency scaling, maybe the OS is in a lower frequency state when not in the app, and therefore takes some time to get up to speed. Maybe @PixelEnvision has no problem with that since he has a lot of background processes running that keep the CPU up and factory resetting therefore did not create the same test environment, but a very different one than on his iPhone. By screencapturing on the device, the throttle is taken away and the CPU is up to speed when opening the app.
    • The app does not switch to the target framerate of 60 FPS even though I'm already setting it again OnApplicationPause. This should be easily testable by setting it every update (and maybe setting it to 30 FPS before to be sure that there are no cached values that ignore changes when setting same framerates). This however would not explain why PixelEnvision had no spikes.
    • The iPhone X has slightly different hardware and/or software settings for different countries. This theory however would be more realistic if PixelEnvision was in the US. Since he is in the UK and I'm in Germany I highly doubt that there are so significant differences that this behavior would differ.
    This is all very, very strange for me. Does anyone have an idea where to go next? I can create a testflight project on Monday so we could compare to the same build to make sure that the building process is not different.
    From the data I gathered I'm not even sure if the problem is on my, Unity's or Apple's side.

    I would highly appreciate if others with an iPhoneX could do the test as well. I also would be very happy for any other insight or thoughts.
     
  10. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    439
    You're welcome. Regarding where to go next, have you tested this with a completely blank new project?
     
  11. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Thanks for the answer, I just got back on it and tried the following:
    1.) Empty scene with setting the targetframerate to 60
    2.) Empty scen with nothing else.

    Interestingly enough, I do see spikes when setting the framerate to 60 (wih nothing else in there), but the spikes are not present in an empty project. I will do a few more tests, but it is interesting, that the problem apparently only appears when running with 60 FPS.
     
  12. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    439
    Hmm, how do you set the project to 60 fps? I saw you mention setting it again on pause, normally setting it once should be enough. Also have you tried different vSync settings? And last thing I would try would be forcing openg2 (if your project allows it) or opengl3 or metal, instead of using automatic selection in player settings. Beyond those, that sounds like an hardware issue since your older builds behaves the same now.
     
  13. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    The script for setting it is really simple:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ApplicationFramerate : MonoBehaviour {
    6.  
    7.     [SerializeField]
    8.     private int targetFramerate = 60;
    9.  
    10.     [SerializeField]
    11.     private bool applyOnStart = true;
    12.  
    13.     [SerializeField]
    14.     private bool applyOnApplicationFocus = true;
    15.  
    16.  
    17.     // Use this for initialization
    18.     void Start ()
    19.     {
    20.         if(applyOnStart)
    21.         {
    22.             ApplyTargetFramerate();
    23.         }
    24.     }
    25.  
    26.     private void OnApplicationPause(bool pause)
    27.     {
    28.         if(!pause && applyOnApplicationFocus)
    29.         {
    30.             ApplyTargetFramerate();
    31.         }
    32.     }
    33.  
    34.     private void ApplyTargetFramerate()
    35.     {
    36.         Application.targetFrameRate = targetFramerate;
    37.     }
    38. }
    39.  
    Setting it again on application focus was an attempt to see if it changes anything, but it is exactly the same (so the spikes are there when I set it once and also when I set it every app switch and also when I set it every update, which I tried as well).

    I tried every blank and no sync, but as far as I know those settings do nothing for iOS, since iOS itself controls VSnyc and you can't change that. Or did I get that wrong?

    Good idea, I tried it with OpenGLES2, OpenGLES3 and metal. Sadly, the spikes show up with all three graphics APIs. Interestingly enough, with OpenGL the spikes don't show GFX.WaitForPresent, but Camera.Render-Drawing-Render.OpaqueGeometry-RenderForwardOpaqueRender-Clear as the root cause.
    Screen Shot 2018-06-18 at 14.37.55.png

    Not quite sure what you mean. The behaviour was the same all the time for me. A hardware issue could be present indeed. :(
     
  14. PixelEnvision

    PixelEnvision

    Joined:
    Feb 7, 2012
    Posts:
    439
    You're right about vSync on IOS but for bugs like this, it worth a shot. :) And I was referring to this
     
  15. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    466
    Ah yeah right, this was/is strange indeed. To be precise, the builds before had the problem as well, then it didn't show up anymore and now it shows up. What speaks against a hardware problem however is, that it runs smoothly with screencapture activated and also other apps built with unity run smoothly on my iPhoneX