views:

496

answers:

2

I am curious to know if anyone has any experience comparing the load time performance of iPhone apps with views laid out in NIBs vs. views laid out entirely programmatically (i.e. instantiating UITextView, adding it to the view, instantiating UIButton, adding it to the view…).

If I want a simple app to load lightning fast, would it be better to forgo using a NIB (well, XIB technically) and instead create view elements programmatically? Is the time spent loading and parsing a NIB sufficient enough to make a noticeable difference?

+2  A: 

In my experience it makes no noticeable difference whatsoever.

And if you think about what's going on with the NIB system, it's a compact binary representation of state of the user-interface objects. By creating the object programmatically, you are only saving the amount of time it takes to load that file and do some very basic parsing. Compare that to the amount of time it takes to initialize and do the first draw of those object (allocating memory for the underlying CALayer objects, drawing them using Quartz2D and then compositing the results together). That time is much greater and it's exactly the same whether you use a NIB or not. If you load a bunch of PNG files to draw your UI, well that will dwarf the time spent on creating the controls.

U62
+1  A: 

I've noticed that loading complex interfaces on the iPhone with NIBs is slightly slower. It's only by a fraction of a second, but it's noticeable if the user is expecting to see a sheet or modal view. I think the difference is that NIBs are lazily loaded on the iPhone, so the view is actually created the first time the view is shown - not when the controller and the view hierarchy are first created. That said, it probably only matters on the iPhone :-)

In general, I'd say NIBs are always worth any performance disadvantages that might exist. I wrote iPhone apps back when the SDK first came out and Interface Builder wasn't well tested. Writing code to create view hierarchies was a terrible mess...

Ben Gotow