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

Massive FPS & Performance Drop Over Time ft. Gfx.WaitForPresent

Discussion in 'Android' started by skeptika, May 14, 2017.

  1. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    I've google'd and read many a forum thread on Android performance issues, especially the Gfx.WaitForPresent threads. Yes, I understand that in many cases Gfx.WaitForPresent taking up time/resources is just fine, it's actually a sign that the game is running speedy, and it is acting like vsync. That doesn't seem to be my problem here, unless I seriously misunderstand something. Let's explain it in pictures.

    Before The Drop.
    All is well, Gfx.WaitForPresent is doing precisely what it should, this is Android, its set to 60fps, and its filling in the gap when the game is ready before it needs to be. Great. No problem here, that's exactly what I'd expect.



    The Beat Drops.
    In case it's not clear, that wall that spikes up, that's Gfx.WaitForPresent. Instead of nicely helping me maintain 60fps, it storms in and utterly decimates my frame rate. Destroys it, 60 slams right down to 30. Note that Camera.Render isn't changing much here, it does seem to go up by about 1ms, but nothing else is substantially changing. No memory increase, no physics weirdness, no crazy spikes, no GC, just Gfx.WaitForPresent.



    What I've tried:
    • This only happens on Android, it does not happen on WebGL or PC.
    • This happens on my Nexus 5X, and an old Nexus 7 (2013), both devices do this. Although both Nexus, they are different manufacturers, phone vs tablet, different years, etc.
    • Every variant of Static Batching, Dynamic Batching, Multithread, Graphics Jobs, combinations or none of the above. Nothing helps.
    • Everything from simple to complex scenes. I've had this happen in scenes that were no more than a flat plane on the ground and a few meshes (no UI etc). It does happen FASTER the more complex the scene. It can go minutes on a simple scene before finally succumbing to defeat.
    • Multiple versions of Unity. 5.5, 5.6, 2017x. They all do the exact same thing.
    • Fixed Time Step changes, under the theory that it simply wasn't making certain timing settings, and loosening them would allow it to not get into this state in the first place.
    • Every Vsync setting possible, Application.targetFrameRate = 60.
    • Reloading the level or loading a new level doesn't change it. Once it's in a degraded performance state, it sticks regardless of level run. This seems very odd to me, that even after the level is unloaded and a new one is loaded, it's still in degraded performance mode.
    • Background the app and coming back does not change it. However, backgrounding the app for a significant time (several minutes) then coming back DOES restore it to normal performance (60fps), temporarily, but then it will do the same thing over time.
    • Why no GPU profiling? B/c this is android and it doesn't appear to let me, I wish it did!
    I put fixing this bug off for a long time, hoping new Unity versions would make it go away. This is literally preventing me from shipping, so I'd truly appreciate any help or insight!
     
    Last edited: May 14, 2017
  2. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    Bumpity, anyone have any idea why Gfx.WaitForPresent goes rogue and starts crushing fps down well below the target frame rate of 60 on Android?

    Been smashing my head against this bug for days, the only "solution" I have available to me is to make the game so performant that even WITH the bug I can maintain 60fps, but this isn't an ideal "solution" :( Am I missing something? Does the profiler suggest something I don't see?
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    This makes it sound like thermal throttling, so by putting it in the background you're giving time to cool off.

    We're seeing similar things, although in our case, putting it in the background for even 1 second, restores performance temporarily.

    Otherwise it is pretty similar. It starts out ok then performance drops. I still don't know if it's thermal throttling, but since the performance drop happens regardless of the scene (from our heaviest to our simplest scene) makes me really not understand what's going on.
     
    Goularou likes this.
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    File bug reports on this.

    There are multiple, long, frustrating threads on gfx.waitforpresent and while some of them seem to have some semblance of solutions I don't think anyone has actually found a real fix for the issue, some random changes made it go away or an update made it disappear for a while for no apparent reason.

    UT chimed in to explain what gfx.WFP is but there are absolutely cases where the reason it is supposed to appear is clearly not why it appears. Because of that, I think it's really important that they get their hands on some hard projects where this is happening so that they can properly track it down, otherwise they're pretty much working in the dark and just assume that it is working as intended - but we simply don't believe them.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    I'd like to be able to narrow it down a bit first.

    Saying "Perfomance bad, please fix" isn't very useful IMO.

    Also, I hope they implement a way to point make a bug report and simply point to the Collaborate project instead of uploading from scratch. It's a lot of gigs and my upload speed sucks so I don't think I can upload my full project easily.
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    Well thats not filing a bug report, thats wasting someones time.

    When I say file a bug report I mean include the project (or a stripped down repro scene-project), build target specifics, repro details, any trial and error you've done, documented results you might have, screenshots, etc.

    A real bug report.

    Yes, collab linking would be nice. I'm not actually sure if they can access the actual stored project files though.
     
  7. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    Necro'n this for posterity. I found the solution, and it may be worth others not having to go to the extreme headache I did to figure this out.

    If you encounter what I did above, either 1) Gfx.WaitForPresent or 2) Device.Present seem to drop your FPS after your game runs for some time, one big possible culprit that is often never mentioned is: thermal throttling. How can you tell if this applies to your performance degredation? Rest your phone (responsibly) on an ice pack, bag of frozen peas, etc. If it no longer degrades, congrats, you unfortunately now know the issue!

    It's not a script problem, not vsync, not a shader issue, memory, transparent geo, optimizations needed, etc. Many modern devices have relatively large resolution screens, and less than ideal thermal construction. This means Unity has to work rather hard to run it at a natively high resolution, generating quite a lot of heat.

    My above graphs represent that at start up, the heat is relatively low, and it runs happily at 60fps. However, as the game continues to run, heat builds up, and Androids thermal throttling steps in to avoid destroying my phone, and it essentially underclocks my phone, causing it to set a new target frame rate of 30fps.

    Any solution? AFAIK there really isn't a great solution here, but the one that works and is at least "acceptable" is to simply lower the resolution of your game. Unity doesn't work your hardware as hard, no thermal throttling, game runs consistently.
     
    Joits, CDUnityDev and LaneFox like this.
  8. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    Wow, great find!

    Thanks for returning with your research.
     
  9. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    I found countless threads having similar problems, all speculating what could be wrong, none having any answers and the threads just died. Went down dozens of crazy rabbit holes, none working. Finally found one where author replied to himself that he put his phone on a frozen bag of broccoli, so I thought "couldn't hurt" and lo and behold... it's an infuriating issue b/c it seems both semi random and semi predictable and all the traditional mobile advice just doesn't apply.

    That said, I do question that Unity runs that hot. I run plenty of 3d games on the phone, at native res, and they don't generate nearly as much heat. Still, knowing at least beats the frustration of having a bug sit around for months that seems unsolvable!
     
  10. henriqueranj

    henriqueranj

    Joined:
    Feb 18, 2016
    Posts:
    176
    Hi @skeptika , I suggest you do some deep profiling and discover what is causing the CPU to overheat. There is this really good talk at Unite 2017 about overheating. Hope it helps (see from 23m30s):
     
  11. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    I'll watch it, appreciate the link with time stamp :) So far he's making my point though "we go to 30fps mostly because of heating." My device, a Google Nexus 5x, while I won't say is an uber high end device, I definitely wouldn't consider it a low end device, the fact that it has to go down to 30fps b/c of heating is...

    As for profiling, I'll dig into the deep profiler but one of the very first things I did was load up an emtpy scene, ran it for a few hours, 60fps. Good. Add in a few meshes with materials... 30fps after awhile. Less than 10 draw calls, less than 5k verts, and it still happens (although it does take longer). I'm doubtful I can "profile" my way out of it, if a minimal scene with nothing more than a few meshes causes it, there's no amount of optimization I can possibly run!

    Regardless, appreciate the link, a fun thing to watch over coffee on my late morning! :)

    Edit: Yup, he's going to end up changing resolution and upscaling, exactly what I figured out you had to do. Nice to have it confirmed at least! Did learn something new though, MSAA is free on mobile?! WTF! Just ran it, seems to be the case... wow!
     
    Last edited: Aug 2, 2017
  12. Joits

    Joits

    Joined:
    Jul 12, 2016
    Posts:
    29
    After banging my head at my desk for a week trying to figure out what this sudden increase in Gfx.WaitForPresent CPU usage was caused by i tried you solution. Frozen peas did the trick! Cant believe it was due to heat (Using a Samsung Tab S2, didnt even feel that warm?!).
    Anyway simply setting a lower framerate using Application.targetFrameRate = 30, made it even more stable.
    Thanks!
     
  13. skeptika

    skeptika

    Joined:
    Dec 31, 2011
    Posts:
    108
    Yah it's why I dug up my old post, I've seen plenty of posts that notice this issue that don't get a meaningful response other than vsync, optimize stuff, you're doing something wrong. I dislike 30fps, to me it feels awful, but yes, you can use Application.targetFrameRate = 30.

    Instead, I use Screen.SetResolution(with true passed at the end) myself to lower the res and upscale it. It means I can rest easier that it's consistently running its best across devices and not subject to random devices with really high screen res and insufficient thermal cooling. That plus adding MSAA back in per the above video, looks crisp and runs great.

    I still find it a bit suspect that Unity runs THIS hot on a high res device. I understand that its significantly down to poor thermal solution on the part of the mobile device, but this happens on some REALLY common devices (several Samsungs, my Nexus, etc).
     
    kartoonist435 and Joits like this.
  14. Goularou

    Goularou

    Joined:
    Oct 19, 2018
    Posts:
    50
    Right on! It took me a while and quite some research to find your answer which is exactly what it was: silence mode on a laptop, overheating and voila... Thanks!