使用 NIB 文件会导致性能损失吗?

发布于 2024-07-26 21:44:10 字数 226 浏览 4 评论 0原文

我很想知道是否有人有经验比较 iPhone 应用程序与 NIB 中布局的视图与完全以编程方式布局的视图(即实例化 UITextView,将其添加到视图,实例化 UIButton,将其添加到视图)的加载时间性能……)。

如果我想要一个简单的应用程序快速加载闪电,那么放弃使用NIB(好吧,技术上是XIB)并以编程方式创建视图元素是否会更好? 加载和解析 NIB 所花费的时间是否足以产生明显的差异?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-08-02 21:44:10

我注意到使用 NIB 在 iPhone 上加载复杂的界面稍微慢一些。 虽然只有几分之一秒,但如果用户期望看到工作表或模式视图,这一点就会很明显。 我认为区别在于 NIB 是在 iPhone 上延迟加载的,因此视图实际上是在第一次显示视图时创建的,而不是在首次创建控制器和视图层次结构时创建的。 也就是说,它可能只在 iPhone 上重要:-)

一般来说,我认为 NIB总是值得任何可能存在的性能缺点。 当 SDK 首次发布并且 Interface Builder 没有经过充分测试时,我就编写了 iPhone 应用程序。 编写代码来创建视图层次结构是一团糟......

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

眼泪都笑了 2024-08-02 21:44:10

根据我的经验,这没有任何明显的区别。

如果您考虑一下 NIB 系统的情况,就会发现它是用户界面对象状态的紧凑二进制表示形式。 通过以编程方式创建对象,您仅节省了加载该文件和执行一些非常基本的解析所需的时间。 将其与初始化和第一次绘制这些对象所需的时间进行比较(为底层 CALayer 对象分配内存,使用 Quartz2D 绘制它们,然后将结果合成在一起)。 这个时间要长得多,而且无论你是否使用 NIB,时间都是一样的。 如果您加载一堆 PNG 文件来绘制 UI,那么创建控件所花费的时间就会相形见绌。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文