Let us put it in this way.
You see an app which is marketed well, obviously with a video in Appstore.
You decides to install it. Successfully installed.
Clicked on Open button in Appstore or clicked the app from springboard of iPhone/iPad.
Nothing showed up for at least 15 seconds.
Result? Instant uninstall.
What you thought, users will stick to it?
People are so busy that they can’t wait too long to see an awesome app.
Don’t make me talk about the reviews they put in because of the launch time.
Really, people do that?
Yes, they do.
Early stages of my iOS career, even I thought if people like the app, they will wait until the home screen of app appears.
They might do but the experience which we expect from those users deteriorate day by day.
We don’t want that to happen in our apps.
This leads to the topic, launch time of an application.
As per Apple standards, launch time can be max 400ms for an iPhone app and 500ms for an iPad app.
There is a time delay when user clicks on app icon from springboard and the launch time. The zoom animation rendering here is taking that time.
Coming to launch types in iOS. There are two types.
This is when your app is present in iPhone and not the initial launch. This means there will be some kind of cache attached to it.
This is when you reset your iPhone and then launch the Application for first time. Cold launch is more important from a user perspective. This is where users will see the application for first time.
First things first.
Let us see how much is your launch time.
1: Go to your Edit Scheme and add this environment variable DYLD_PRINT_STATISTICS with value 1. Screengrab shown below
2: Now run your app and you will be seeing something similar to below
Total pre-main time is the exact launch time for your application. If you can reduce this time to some 400milliseconds, much better.
Tips you want to take to reduce the launch time
1: Attach less embedded libraries. Remove those dylibs which are not at all used in the App.
The more embedded libraries, it will take more time for the system to load those in the memory even before calling your applicationDidFInishLaunching.
Addition to this, start using static archives.
2: Reduce C++ virtual functions
Try reducing C++ virtual functions as it will eat up more time in launching the app.
3: Use Swift
Swift code generation is better than Objective C.
Making use of Swift structs in your application will help in reducing the launch time. (This is what Apple says)
4: Using less codes in initialize method.
Initialize method is the one which loads much before viewDidLoad.
Less initialisation of objects in this method lower the time.
5: Have seen in many codes that we tend to use smaller classes, with single functionality.
Yes, it is good for readability and to maintain the code. But Apple recommends to consolidate these kind of classes. If your application contains some 10000 classes (which many apps do), reducing some 1000+ classes will result in a good way.
6: And last but not least, keep your
applicationDidFinishLaunchingWithOptions as light as possible.
Strictly NO file fetching or expensive operations to be done on that method.
Remember, if your app takes more than 20 seconds to launch, OS will terminate your app, thinking it went for indefinite loop.
No body likes a slow app, lets make it better or at least make the user believe that it launched quickly.
For in depth analysis and how you can make your app faster, refer following WWDC video.
Clap below if you like this post and comment your thoughts.