Performance penalty for using NIB files?

前提是你 提交于 2019-12-05 11:56:23

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...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!