Slow launch on iPhone

I am debugging the slow launch of an iPhone application (Xcode, Objective C ++). This is a tab-based application with three tabs. All three tabs are loaded into one NIB - about 20 objects in total.

The first round of significant initialization occurs in the viewDidLoad handler of the first tab view controller. However, between the main () and the start time of this method, it takes about 1 second - about 2/3 of the total load time. Question: what happens during this time, and how can I investigate this (without waiting for disassembly)? As far as I know, between two points there is no my code - the delay occurs completely in the system code.

Maybe some Tool that can give me a time profile for each function?

The package is ~ 4 MB, but I upload the largest file (~ 3.5 MB) later than this to the applicationDidFinishLaunching handler. Removing this file from the package and commenting on the corresponding code does nothing for this 1 second delay.

UPDATE: still there was a debugging intervention. If I launched it on the device while watching the console, the launch time is much shorter, and the proportion of the system delay code on my code is also distorted. But, nevertheless, there is a noticeable delay between main and viewDidLoad, and this is about 50% of the total load time.

By the way, of all the methods of loading a fairly large file from a package into memory, the fastest of them was direct memory mapping (using POSIX mmap ()).

+4
source share
4 answers

There are two things here. If you are debugging your application from Xcode, there is a good chance that the application is waiting at startup to connect to the GDB debugger. In my experience, this takes about a second. Try running the application without saying β€œBuild and Go” in Xcode and see if the results are the same. (Just tap it from the main screen)

Your NIB file may also be a problem. 20 objects are not so many, but you can consider hacking each tab into a separate NIB file if all else fails. The contents of the NIB files referenced by your main NIB file are easy to download, so the application does not load views for the two invisible tabs until they are selected. This may give you a boost in startup performance, although I don't think it could be a full second.

Apple has some great performance analysis tools in the iPhone SDK, but it's a little hard to find. From the Run menu, select Run with Performance Tool β†’ Sampler CPU. This will launch a standalone application called β€œTools,” which will allow you to perform all kinds of excellent runtime analysis. When you have the CPU tool selected, the bottom half of the Tools window provides a breakdown of what the processor time took in your application. You can double-click on functions to immerse yourself in them and get a breakdown of the lines in% of the cycles used. He should give you more information on what specifically causes your problem.

+4
source

If you are really interested in knowing what is executed at startup time and the relative time that each method takes to run, you can create your own DTrace script to track this. I describe how to do this at the end of this article . This script will show you every method executed by your application, from the time it starts to the end of -applicationDidFinishLaunching :, along with the time spent in this method. You can run this script as a custom tool in Tools or as a stand-alone script (a stand-alone script tends to be more accurate on a system under load).

The main caveat of this approach is that it will only work in Simulator, given the current lack of DTrace support in the iPhone itself. However, you should be able to extract the order in which things are done when your application starts, as well as the time that your application spends on each method. It will even show closed private API calls that are created as your application launches, which may give additional hints as to what is happening.

For additional suggestions on customizing the launch, I would recommend reading the article by James Thomson "How to quickly launch your iPhone application . "

+4
source

If you find that your xib files are too large, I advise you to create your own interface with clean code. large xib files will certainly slow down startup time and also slow down your application when you first use an object in your xib.

I do not use xib in my projects, because when someone changed xib in svn, you are unlikely to find what has changed. This means that xib is not suitable for SVN.

0
source

I would recommend splitting your application into three NIBS; the tab bar and the controller of the tab bar are displayed at startup in the first, and then lazily load the other two when the user first switches to them.

I believe that you can use the File -> Decompose Interface function in Interface Builder to accomplish this.

0
source

All Articles