Time profiler shows the most time consuming operation in my app is loading UITableViewCells
from nib files. The most expensive of which involves loading a UITableViewCell
with a 4KB image.
I am loading the UITableViewCell
from the nib with the following code:
[[NSBundle mainBundle] loadNibNamed:@"UITableViewCellPortrait" owner:self options:NULL];
cell = portraitCell;
self.portraitCell = nil;
Has anyone compared the difference between creating a view programmatically or loading a UITableViewCell
from a nib?
EDIT:
I compared the time profile of repeated runs of loading the UITableViewCell
from a nib and creating the view programmatically. My test involved alternating between two UITableViews
about 10 times in the span of 3-5 seconds. In each test, loading the UITableViewCell
programmatically was substantially faster, between 2x to 6x faster.
Can anyone corroborate these results?
EDIT: I updated the nib loading code to only load the nib file once and use a cached version for subsequent calls.
if (self.UITableViewPortaitNib == nil) {
self.UITableViewPortaitNib = [UINib nibWithNibName:@"UITableViewCellPortrait" bundle:[NSBundle mainBundle]];
}
self.UITableViewPortaitNib instantiateWithOwner:self options:NULL];
cell = portraitCell;
self.portraitCell = nil;
I also used the automation instrument to create more consistent runs and the results still suggest loading UITableViewCells
programmatically is faster than loading UITableViewCells
for a nib. The average running time for loading UITableViewCells
from a nib was around 90ms, while the average running time for creating the UITableViewCell
programmatically was 50ms.