How we saved 3.7 years of our customers

By – Vivek Singh (Engineer, Android)

UC Blogger
Urban Company – Engineering
4 min readAug 21, 2019

--

Photo by Aron Visuals on Unsplash

At Urbanclap we are striving to build the largest home services marketplace in the world. Engineering is driving this growth churning out features for our customers and building scalable platforms for the product and business teams.

At this scale optimising for every millisecond has a significant impact on our customers .This post is a journey about how we revamped our android apps startup, effectively reducing the cold start time by 37%.

This marked a major milestone in the overall goal of building a feature-rich and performant app that our users love.

Cold start comparison

What is Cold start?

Quoting the official documentation :

A cold start refers to an app’s starting from scratch: the system’s process has not, until this start, created the app’s process. Cold starts happen in cases such as your app’s being launched for the first time since the device booted, or since the system killed the app

In short, this is the time that the user has to wait after clicking on the app icon. At the beginning of a cold start, the system has three tasks. These tasks are:

  1. Loading and launching the app.
  2. Displaying a blank starting window for the app immediately after launch.
  3. Creating the app process.

As soon as the system creates the app process, the app process is responsible for the next stages:

  1. Creating the app object.
  2. Launching the main thread.
  3. Creating the main activity.
  4. Inflating views.
  5. Laying out the screen.
  6. Performing the initial draw.
Important parts of a cold start

App Startup flow — Then

App start flow of older apps

The above flow served us well but had the following limitations

  1. Our application class was cluttered with initialization code and became a monolith
  2. On-boarding Activities were not integral to a logged-in user but were still created and quickly destroyed, adding to startup time.
  3. We had a compulsory 3-second timer on Splash activity to wait for configuration APIs. Even though the cold startup time was 800ms, the time actually taken for the user to land on home-screen was almost 4 seconds due to this. It was the single biggest bottleneck in the whole flow and we needed a different way to handle configuration APIs.

App startup flow — Now

App startup flow now

What did we do to achieve better startup times?

  1. Moved all library initializations to a separate thread i.e. AppInitializer
  2. Removed main thread blocking tasks. Some were made lazy, others were moved to AppInitializer.
  3. Created a mechanism for the main thread to post tasks to the Initializer thread if a library was not initialized but its need arose on the main thread. This was the most critical piece to figure out and really gave us the ability to shift everything to AppInitializer
  4. Removed SplashActivity. Made HomeActivity as the launcher activity.
  5. Created OnboardingManager to manage onboarding. No more unnecessary activity creation and destruction
  6. Created AppInitApiManager which handled API results reactively instead of waiting explicitly for 3 seconds.
  7. Simplified Home screen layout for faster inflation
  8. Converted PNG images to WebP

Results

Firebase performance SDK was used to compile the following data

Median Cold startup time old — 791 ms
Median Cold startup time new —
500ms

Effect

Since the time of launching this feature in January 2019, the app has been started 38,774,534 times.
That is about 1365 days or 3.7 years users have spent going through the content of the app instead of looking at the splash screen.

And our users share the same enthusiasm as us.

About the author: Vivek Singh – a full time Android geek, a part time PUBG fanatic. He likes to deep dive into any form of code, but shies away from any form of exercise. Vivek takes care of the storefront on the customer android app.

Sounds like fun?
If you enjoyed this blog post, please clap 👏(as many times as you like) and follow us (UrbanClap Blogger) . Help us build a community by sharing on your favourite social networks (Twitter, LinkedIn, Facebook, etc).

You can read up more about us on our publications —
https://medium.com/urbanclap-design
https://medium.com/urbanclap-engineering

If you are interested in finding out about opportunities, visit us at http://careers.urbanclap.com

--

--

UC Blogger
Urban Company – Engineering

The author of stories from inside Urban Company (owner of Engineering, Design & Culture blogs)