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

Question Optimise game startup time

Discussion in 'Android' started by Thorax-, May 18, 2023.

  1. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    My questions is regarding optimisation of app startup time. On lower end devices the initial black screen before the first scene is loaded is about 5-8 seconds. I know i should be able to get a faster startup time because on another project of similar size and setup the startup takes only 3-4 seconds.

    Here are some project specifics and things i have tried so far to improve this initial loading time:
    Currently using Unity 2020.3.30f1, Firebase services, Google Play services, Google Admob, Unity IAP, Addressables, Universal RP

    The first scene is almost empty. It contains only company's logo, 3-4 Image components. There is no initialisation performed in this scene. All it does is load asynchronously the next scene using Addressables.LoadSceneAsync. There is only this scene in the build settings as all others are loaded through addressables.
    I was recently implementing the Addressables in an attempt to improve the startup time as well as the overall performance of the game. Performance improved but startup time is still slow. I spent a lot of time to ensure I have no duplicates between bundles, bundles and resources and so on. Here are the results:

    Screenshot 2023-05-14 at 12.05.51.png

    Resources folder of the project is empty. Some packages have their own Resources folders but with very little files and no references to anything in the asset bundles. I had to keep an embedded TMP package to get rid of the duplication coming from the Resources folder of the TMP package but this is solved now.

    Another thing i did was to use IPreprocessShaders to disable the compilation of all the shaders coming from URP. I am not using post processing but there are some shaders which are included in your build regardless. So with stripping all the shaders from URP I still get no improvements in the startup time.

    Any help would be greatly appreciated. I have been searching the web for anything related but it all comes down to the things I described and I already tried those. I can post any additional info if required.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,402
    Check the profiler on the android build and see what takes up the frame time
     
  3. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Thanks for your reply!
    First of all here is the code executed in my first scene:

    Code (CSharp):
    1. private void Start()
    2.     {
    3.         StartCoroutine(Init());
    4.     }
    5.  
    6.     private IEnumerator Init()
    7.     {
    8.         while (!Caching.ready)
    9.             yield return null;
    10.      
    11.         Launch();
    12.     }
    13.  
    14.     private void Launch()
    15.     {
    16.         if (!PlayerPrefs.HasKey("gdpr")) ScenesLoader.LoadSceneAsync(ScenesLoader.GDPR_Scene_Index);
    17.         else ScenesLoader.LoadSceneAsync(ScenesLoader.Init_Scene_Index);
    18.     }
    It is waiting for caching to be ready before asynchronously loading the next scene.

    Here are the first 2 frames showing up in the profiler window:

    frame 1.png frame 2.png

    And here is the PostLateUpdate.FinishFrameRendering in frame 2 expanded (it is from a new session thats why the time in ms is slightly different in the 2 photos):

    frame 2 expanded.png

    At frame 2 my first scene is already rendered. This is a build with Unity splash screen as I dont have a key to remove it but the delay is not related to the splash screen as it exists in a signed build as well. Do you see anything abnormal in the profiler?
     
  4. Thorax-

    Thorax-

    Joined:
    Feb 10, 2021
    Posts:
    20
    Testing on Lenovo Tab 7 the first time you launch the game it takes 16 seconds. And for next starts it only takes 4 seconds (significantly smaller amount). Tests are from a signed .aab. So something needs to get cached and it is cached during the first launch. Can anyone shed some light on what that could be?