Speed up loading UI from NIB on iPhone
First of all I understand that this app has some design issues and rewriting a huge chunk will probably solve my problems, I'm looking for a way to speed things up right now.
Basically I have
viewController = [[MyViewController alloc] initWithNibName:nil bundle:nil]; viewController.view;
where MyViewController.xib is a rather complex nib file with many intertwined controllers and views, some of which of course load their views and hierarchies from other pens, but of course not all. It takes about 7 seconds to load, which is very long considering this is an iPhone app.
The reason for force loading the view is that I am also doing some network requests in a parallel thread, and once they run out, I would like to create quite a few things with these views.
My question is, how do I know which parts of my nib are taking so long, and what would be the best strategy to optimize it without completely rewriting the entire application (for now)?
a source to share
The first thing to do is not to assume that loading nibs is a bottleneck without direct evidence that it is. Thread loading is highly optimized and very efficient. Chances are your bottleneck is network request than feathers. Use tools to get specific data on where an app is spending its time before doing anything.
Assuming these are nibs, Andiih's answer is the best for profiling, but it sounds to me like you actually have a design problem.
It looks like you need to break your large nib into smaller nibs.
Its common to have one kind of nib. For example, suppose you have an application that has a tab with five tabs. Then there was a table view in each tab which would open the detail view. In a typical setup, you will have 11 separate tips. One nib will define a tab, one nib for each tab, and then one icon per detail view. When the app starts, only the tab thread and the first visible tab will be loaded, so you only have to load two of the 11 pens.
To optimize, the first thing to do is to break it down into the smallest possible custom nibs. The loading tip is loaded if necessary. You should place functions in all of your nips so that you don't load the nip if its view is not immediately displayed.
Nibs are just lightweight data files, so don't be afraid to create socks that are 99% identical. For example, I often use separate views for each portrait and landscape view. For a user perspective, this is one view, but I have three separate tips. I do this in cases where it's easier to use a completely separate view than rotate one complex view. Each tip is loaded when its orientation is used. If the orientation never changes, it never loads.
If you have a complex interface that changes significantly depending on the network request, at runtime the runtime will have separate nibs for each option, which will hammer all the functionality into one nib.
a source to share