The fascinating story of 6X improvement in redBus iOS App Launch time ~ From 1.6 Seconds to 268 milliseconds

Subhodip Banerjee
redbus India Blog
Published in
4 min readJun 28, 2020
Credit: redBus

We were facing a challenge to reduce the app launch time in iOS. While checking out, We found our redBus App takes 1.6 seconds to launch. That’s more than what Apple recommends ~ 0.4 seconds for iPhone and 0.5 seconds for iPad.

Please find the link for WWDC videos here — — — →

[https://developer.apple.com/videos/wwdc2012/#225]

If you wanted to look into this -> go to Xcode -> Edit Scheme -> Env Variables -> Add DYLD_PRINT_STATISTICS as Yes/1. -> Run Xcode will get the pre main time.

So, when we launch any application. We need to rely upon mainly 3 things:

  1. Network Latency [If at the time of App launch we are calling any Backend API]
  2. Backend Response Data packet optimization [The size of the json[Bytes] we used to receive from Server]
  3. Client[here our redBus iOS App] Pre-Main + Post-Main time.

In this post, We improvised client-side changes[Point no. 3] which helped to reduce this delay significantly. Let me walk you through these changes.

How We have reduced from 1.6 sec to 268 milliseconds?[Warm Launch]

Disclaimer: The following stunts are performed by highly trained professionals under expert supervision, plz don’t try this in your iOS Projects. Haha, Kidding. It’s easy, just follow the below steps :)

1. We used static-libs replacing the use of existing dynamic-libs.

2. We deleted NSLog and Print statements wherever required.

3. During the launch time, we call third party SDK’s in the Main thread which leads to delay and is irrelevant for some SDK[like Analytics and logging]. So we moved some of the SDK to the background thread.

4. We migrated the UI Updates to the Main thread at App launch, wherever missed.

So, as per the analysis, the main part which was taking more time was dynamic libraries.

Now let’s have a glance at the Xcode Data :
Before — →

Source: Xcode

After — →

Source: Xcode

Here’s the pictorial comparison below with before and after together:

Credit: Self

Here are some tips to produce static libs instead of dynamic libs:

  1. Go to your project, remove Xcode Workspace, Podfile.lock and Pods Folder.
  2. Inside Podfile Comment #use_frameworks[this is useful for Dynamic libs[Basically comment it out.]], add use_module_headers![which helps for static libs].
  3. If you’re using React Native inside your project, like pod ‘DoubleConversion’, Just add :modular_headers => false [else at the time of pod install it will throw an error]
  4. After this, If you’re using react native, delete node_modules and package-lock.json and then do npm install.
  5. Next, pod install.
  6. Still you may get some errors at the time of building the project. For our case we got issue for SQLite bridging headers and react native maps. Solved it by #import “SQLite-Bridging.h”[Inside SQLite.h] ,#import <React/RCTGIFImageDecoder.h>[lib/ios/AirMaps/AIRMapMarker.m] and #import <React/RCTGIFImageDecoder.h>[lib/ios/AirMaps/AIRMapOverlay.m]
  7. If you get some more errors just check the doc/github for the particular library or else dig dive into it[hit me up if you need help].
  8. Restart your phone and run the project. That’s it for Static libs Still you will see some improvements not the most as it involves pre-main + post-main.
  9. Now, launch instruments. Start time profiling, Trace the call tree and identify the places for the time is taking more and go deeper in depth.Check where the Main thread is taking much time to execute. Just deep dive and optimise it and that’s all you’re There.[This will take some time if you’re in a big project, So be wise and take your time]
  10. You’re done!

So here is our journey to reduce the 1/6 time of iOS App launch after doing all of our stunts[1.6seconds to 0.268 milliseconds].

It’s drastic, isn’t it? Don’t forget to share your thoughts in the comment section :)

We are still digging into this. We will keep working on this till we can hit 160 milliseconds[Fingers crossed]. Hopefully, I can share the Good News with you soon.

Thanks Phaneesh for reviewing and sharing your valuable thoughts, wherever I have missed.

Thanks for investing your valuable time Guys :)

--

--