Search Unity

Better performances after game has been put in the background??

Discussion in 'Android' started by mikapote, Jul 17, 2020.

  1. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    Hi there. Ok, very weird behavior I've found here. On a Huawei P10, when launching the game I encounter some big spikes in the profiler (VSYNC wait for a long time), when it seems that the app could run easily at 60FPS (see profiler below).

    Screen Shot 2020-07-17 at 13.55.09.png

    BUT when I put the game in the background then bring it back in the foreground, the spikes are gone and the frame-rate is 100% smooth.

    upload_2020-7-17_13-56-38.png

    I obviously made sure to also build a non-development version, but the "lags" remained. And there again, after taking the game in the background and re-opening it, no frame-rate drop anymore.

    Any clue about the potential cause of all this? Have you witnessed this behavior in your app?
    I'm using Unity 2019.4.4f1.
     
    Last edited: Jul 17, 2020
  2. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    Ok, so the weirdness continues. There's another way to stabilize the frame-rate and avoid those drops: by enabling profiling through adb. Yep: as soon as I start profiling through the usb connection, the game is smooth.

    How can this be possible? I'm really stuck here, can't see how putting the game in the background or profiling through USB could help with the frame-rate.. but it does.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Hi there,

    I don't really have any good answers for you either but just some potential ideas:
    • Thermal Throttling is a thing, so putting the app in background could give your phone time to cool down and then run faster after? Try putting it into the fridge for a bit before testing to see if it plays a role?
    • Sending Profiler data over the WIFI instead of USB might have an impact on the performance?
    • Being connected to a power source (USB) might have an influence on the phones power management logic?
    • Could be that an open adb connection changes power/performance management?
    besides that, is there anything that stands out in Timeline view for the frames with these spikes or the frames before them? (or in Hierarchy view when switching through the frames, main point being to look outside of the main thread too)

    Could also be interesting to load that capture data into the Profile Analyzer for comparison and see what sticks out after eliminating vSync from the comparison, possibly with a look at the Rendering thread. If it just all takes a bit longer, it's likely thermal throttling, maybe it's just the GPU though so that would be harder to spot directly in there...
     
  4. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    Thanks a lot for your answer Martin and the interesting points that you raised!

    I'm not sure about thermal throttling, because all I need to do to get stable 60FPS frame-rate is to put the app in the background for like 2 seconds: the device doesn't really have time to cool down. And when I re-open it, the frame-rate stays stable, even if the device becomes hot.
    It might be a Huawei specific - power management thing...

    I'll take a look at the Profile Analyzer, I didn't know about this tool! And I may come back soon with some more in-depth Timeline analysis.

    I've finally released a new update for my game after spending days optimizing it, I want to see if I get some complains regarding performances before optimizing further ;) Here it is if you wanna try: https://play.google.com/store/apps/details?id=com.cutloop.BlockScout
     
    MartinTilo likes this.
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    whoo! nice game. Running butter smooth on my OnePlus 6 right from the start btw
    (This might actually be a game that might stick with me for a while)
     
    mikapote likes this.
  6. mikapote

    mikapote

    Joined:
    Oct 24, 2018
    Posts:
    28
    Haha, thanks so much Martin! Really cool to get feedback like this one from a Unity dev :)

    (PS: Just note that there's an annoying bug with the save system that is going to be fixed in the next update, which is currently being deployed... so maybe wait for this one (0.72) before trying to reach the top of the leaderboard :D)

    Regarding my issues, I'm investigating the use of Jobs (and maybe ECS) in the cases where the game is CPU bound. Might help with physics computations and instantiation of blocks.