How to debug slow app launch

China☆狼群 提交于 2019-12-30 10:28:45

问题


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?


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/36240399/how-to-debug-slow-app-launch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!