I finally got the time down to a reasonable amount. Here’s how I tested and what my solutions were:
Finding out what is slowing down your app
Examine your blocks to find out which of them are executed when the app starts. Divide the code into meaningful parts and mark each section with a log block like so
Plug your phone with the app installed into your computer and start logcat (Full guide). For me (Windows & info level) the command is .\adb logcat *:I
. Then take a close look at the output. For best results, I recommend copying the output with Shift+Ctrl+C into a text editor. You can then easily filter and format the logs. You’ll then have to calculate the runtimes for each section using the timestamps. Write them down to see where times can be improved
Improving app startup time
Here are some methods I used to speed up the app
Cache values globally
Does your app need the same values on every start? If you do not expect them to change often, you can save them in a TinyDB
Cache values locally
Do you have static values or values that are needed in every loop? Better store them in a variable
Sorting
Sorting isn’t trivial, so use a sorting algorithm with good performance. Quicksort is fine probably
Lazy loading
Retrieve values only once they are needed
Lists
Do you really need to load the whole list? Try to load what the user sees first and more items later
Conclusion
I was able to reduce the app start time from 20 seconds to three. That’s almost seven times faster. I’m happy to say that neither the tabs layout from Kodular nor my I18n extension were the cause of the slow app start.