iOS App Performance enhancement — Launch Types and App Launch Time

Users expect every application’s response to be fast. If the application is slow then it will disappoint the users. Because of this users may give low rating to your app in app store.

This blog helps you to reduce the application launch time. Before going to detailed explanation about of how to reduce the application launch time, it is necessary to know about internals of application launch process.

Application launch will take place in one or two states, each affecting how long it takes for your app to become visible to the user: cold start, warm start

  1. Cold Launch: In this your app starts from scratch. that means app is not in the system kernal cache. that means app is killed by system or device booted.

At the initial stage of cold start, system will take care of three task:

  1. Loading the application.
  2. Application launch and display the lauch screen to user,
  3. Creating the application process.

Application process will take care of creating application object, launching main thread, creating main activity, laying out the views and performing initial draw.

2. Warm Launch: In this launch your application will be reciding in system cache and when launched, it will come to foreground from back ground. Ideally this is pretty fast compare to cold launch time.

When developer talks about application launch time we have to consider cold launch time only.

When we talk about applicaiton launch time (Cold launch), we have to consider two main factors. Pre main time and Post main time.

  1. Pre main time: This time is before the UIApplicationMain is returned i.e func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { return true }

another way you can say like this is the time before when the application’s main() method called and you get control on the app by os

we can analyse the pre main time using : DYLD_PRINT_STATISTICS

Steps: Go to Edit Schema -> Arguments -> Under Envirnoment Variables add DYLD_PRINT_STATISTICS -> set DYLD_PRINT_STATISTICS to true

this pre main time will print in your console as: Grayed out is our complete app taking 604.40 ms for set up

2. Post main time: this time is after UIApplicationMain is returned. In this time you have control on the app by os. this time will be calculated as time taken to launch our first home screen

we can analyse the post main time using Date(): print the current Date before return statement in didFinishLaunchingWithOptions method and viewDidAppear() method of your initial view controller. Take the difference of these two date will give the post main time.

conclusion: Finally, our app launch time depends on pre main time and post main time. To optimise app launch time we have to consider the worst case i.e: cold Launch. App Launch = Pre main time + Post Main time

Read this blog to know how to reduce the pre main time of iOS app launch time

LAST REMARKS

I hope you have learned something valuable from my article. If you have then let me know by hitting that ❤ button and follow me on Medium.

Like what you read? Give Manasa M P a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.