ilan
ilan

Reputation: 4462

How to debug slow app launch

When launching my app i get the launch screen for about 2-3 seconds and only then my first UIViewController appears.

And some times my ViewDIdAppear is being called before the UIViewController is actually appearing.

I have a pretty big storyboard (15 screens).

I have some flags that i check from UserDefaults (user is logged-in ...), and i initialize crashlytics and GCM.

So the flags and the initializing doesn't seem to be the problem.

I checked system time differences and it seems to be OK.

Any ideas for debugging the slow launch?

Upvotes: 3

Views: 3012

Answers (2)

Jon Rose
Jon Rose

Reputation: 8563

The time profiler will not help you if the slowness is from the initialization time. During that time none of your code is running yet, so the time profile won't be logging anything. You can have xcode print out stattics on how long it take to launch by going to 'edit scheme' -> run -> environment variables add add DYLD_PRINT_STATISTICS with a value of 1. Ideally you want your launch time to be less than 400ms which is about the length of the opening animation. I was able to cut my launch time in half by removing use_frameworks! from cocoapods. And I was able to to cut it in half again by removing unused external libraries.

There is a great apple lecture on the topic here: https://developer.apple.com/videos/play/wwdc2016/406/

Upvotes: 1

David
David

Reputation: 2659

In Xcode: Product -> Profile

Choose the "Time Profiler"

Running this tool will give you time spent in every method in your program, and it'll give you that information in a hierarchical structure. This should give you an idea where most of the time is spent. Keep in mind that the instrumentation adds extra overhead, so the absolute time value may not be correct, but the proportion of time spend in each method should what you need to debug this issue.

Here is a decent looking tutorial (albeit on an older version of Xcode) showing how to use this tool.

enter image description here

Upvotes: 5

Related Questions