Startup time is one of the most important metrics for an app. It is also one of the most frustrating things to optimize. There are many factors that go into making your Android app start up quickly, and it can be difficult to find which ones are impacting your startup times without profiling tools. If you’re not careful, code optimization could even hurt your performance due to increased memory usage or other side effects! This article provides information on launch time optimization.
Application launch can take place in three states: cold start, warm start, and hot start. For the cold start, the app starts up from scratch while the warm and hot starts bringing the app running in the background to the foreground.
When optimizing the startup, it is much better to optimize based on a cold start. The cold start takes the longest time so optimizing this can also improve the start-up times of the warm and hot starts.
To optimize your application for a faster launch time, it is important to know what’s going on at the system and application levels and how they interact with the 3 states.
Cold starts occur when your app is being launched for the first time since booting your device, or since the system killed the app. This type of start presents the greatest challenge in terms of minimizing startup time because the system and app have more work to do than in the other launch states.
In the hot start, the system just has to bring your application to the foreground. The application’s processes are still present in the device memory so this takes a shorter time.
When your application has a problem, the android has different ways of making you aware and aiding in diagnostics. Android vitals alert you to the occurring problems and diagnostic tools help in diagnosing them.
Android vitals tell you when your app start up times are slow (more than 5 seconds for cold start, more than 2 seconds for warm start, and more than 1.5 seconds for a hot start).
To properly diagnose launch time performance, you can track metrics that indicate how much time it takes your application to launch. Analyze the time to initial display, time to full display, make sure to identify bottlenecks in the startup process (A good way to look for bottlenecks is to make use of the Android Studio CPU Profiler).
Ensure your application only initializes objects that are instantly needed. This reduces the problem of heavy app initialization which affects launch time.