Search code examples
androidperformanceoptimizationstartup

Why do some android apps start so quickly?


I've recently taken a look at logcat and noticed that my apps take more time to start than other do. Then I've created a new project with an empty activity, but it is still slower than some other apps.

2021-07-20 21:28:17.750 1321-1344/? I/ActivityTaskManager: Displayed com.tutaf.myapplication/.MainActivity: +956ms

For comparison:

  • Telegram X starts in 400-500 ms
  • Firefox: 550-1000 ms
  • VLC: 700-900 ms
  • 4PDA: 400-600 ms
  • Total Commander: 600-800 ms

Why do these apps start faster than an empty app and is there a way to get closer to their result?


Solution

  • After investigation of the logcat, I have found that during application's Make-Span(initiation to display). it suffers from several Time Consuming Operations. Moreover, if you mitigate these intense operations, you would be able to speed up the application startup. In the below, I have clarified the problem:

    2021-07-20 22:43:50.730 => ok
    2021-07-20 22:43:50.730 => ok
    2021-07-20 22:43:50.748 => ok
    2021-07-20 22:43:50.749 => ok
    2021-07-20 22:43:50.750 => ok
    2021-07-20 22:43:50.792 => spike : 42ms 
    2021-07-20 22:43:50.793 => ok
    2021-07-20 22:43:50.820 => ok
    2021-07-20 22:43:50.822 => ok
    2021-07-20 22:43:50.843 => ok
    2021-07-20 22:43:50.884 => spike : 41ms
    2021-07-20 22:43:50.895 => ok
    2021-07-20 22:43:51.170 => spike : 275ms : INTENSE
    2021-07-20 22:43:51.171 => ok
    2021-07-20 22:43:51.173 => ok
    2021-07-20 22:43:51.188 => ok
    2021-07-20 22:43:51.189 => ok
    2021-07-20 22:43:51.340 => spike : 151ms : INTENSE
    2021-07-20 22:43:51.341 => ok
    2021-07-20 22:43:51.481 => spike : 140ms : INTENSE
    2021-07-20 22:43:51.481 => ok
    2021-07-20 22:43:51.494 => ok
    2021-07-20 22:43:51.550 => spike : 56ms 
    2021-07-20 22:43:51.551 => ok
    2021-07-20 22:43:51.676 /.MainActivity: +943ms
    

    Accordingly, if you mitigate INTENSE spikes (275ms +151ms + 140ms = 566ms), application's startup takes 377ms (943ms - 566ms), the startup time that you've expected.

    Recommendations

    • Do not make a fat Main Activity
    • Do most of operations async
    • Do not Data-Intense operations on Main Activity
    • Do not put too many graphical elements in Main Activity's UI
    • Make your Main Activity as light-weight as possible