views:

52

answers:

3

I'm currently developing a client similar to twitter. The app has 5 tabs, and are all table views controllers.

It seems simple enough, but the start up time (from hitting the app on the menu..to the black screen+status bar ...to the user interface) is 18 seconds!

I want to slice this down to at least 5-6 seconds and don't want to have a splash screen. Can someone please give me some pointers on how to bring up the UI faster? E.g. Certain methods I should be using / correct spots where I should be making API calls?

(P.S. right now almost 90% of my initial API calls are being made in the (id)init{} method)

A: 

You should first add some NSLog timestamps to see where exactly you're losing all this time. Then it will be more clear what can be optimized.

sha
right now, I'm implementing synchronous API calls and have all my tabs being instantiated right at the start of the app. Going to switch the connection type and lazy load the tabs and see if that speeds things up..
dpigera
+1  A: 

One of my apps has five tabs as well (but only three table view controllers), and it starts up in aobut 6 seconds (as you're trying to achieve). I've noticed that only the contents of the first tab are loaded on startup. The remaining ones are loaded when you touche the tab for the first time.

So the clue could be to make sure your tabs are initialized lazily, and I'm guessing this is not yet the case with your app. My app has 6 XIB files, one for the main window and 5 for the contents of each tab. Is your UI organized the same way?

Assuming your UI is not loaded lazily, you could set breakpoints in the viewDidLoad: methods of your tab contents and see who is loading them so early.

Codo
oh wow. that might definitely help. I actually have all the tabs instantiated at AppDidFinishLaunching.. that might definitely speed things up.
dpigera
+2  A: 

Running through the debugger adds a lot of time to the start up. Have you timed it running off a regular start? It sounds like this 15-20 seconds is your time while running through the debugger, since the bootstrapper kills off apps that take too long to start up.

Aside from that, it sounds like you're doing API calls during the start up as well. Are these synchronous or asynchronous API calls? You'll probably want to be doing asynchronous API calls, since blocking the main UI thread is a big no-no. If they are synchronous calls, an easy way to get around them is to pack them in a single method and then use [NSThread detachNewThreadSelector:toTarget:withObject:].

Once all your data is loaded, just update the UI with the new data (but make sure to do it in the main thread, since touching UI elements outside the main thread is another big no-no. Using [NSObject performSelectorOnMainThread:withObject:waitUntilDone] is one way to do it.

David Liu
I got all my calls running through synchronous calls. When the connection is completed, I have a delegate setup to inform the view to reload itself.. Will I have to change this if I switch to asynchronous?
dpigera
Not at all. It would most definitely help if you posted an example of what you are doing, but from what it sounds like, your setup is fine. You just need to ensure that you perform any UI-related tasks on the main thread.
David Liu