winsLayer的NSView性能(NSView performance of wantsLayer)

系统教程 行业动态 更新时间:2024-06-14 17:03:52
winsLayer的NSView性能(NSView performance of wantsLayer)

如果我创建一个空白的Mac XCode项目并在主窗口中并排布局500个简单的NSView对象,它的加载非常快。 如果我在每个子视图上设置wantsLayer=YES ,性能会急剧下降几秒钟。 为什么这是概念性的? 看起来层会比常规的旧NSView更快而不慢。

If I create a blank Mac XCode project and layout 500 simple NSView objects side by side in the main window it loads pretty damn fast. If I set wantsLayer=YES on each subview, performance dramatically drops, by several seconds. Why is this the case conceptually? It seems that layers would be faster not slower than regular old NSViews.

最满意答案

您可以通过分层支持这么多视图为系统提供更多工作。 图层加载允许图形加速(用于绘图),但它为布局等内容增加了一些开销,更不用说创建它们并将它们放在屏幕上 。 如果使用得当,这并不是什么大问题。

通常情况下,如果您在屏幕上同时管理了很多“事物”,那么您将拥有一个层支持的托管视图来管理其自己的子图层树。 “但基于视图的表格视图呢?” 你问。 诡计, 诡计 ,我说! 表视图实际上并不保留它们管理的所有单元视图; 他们有效地重复使用它们,只保留足够的空间以表示屏幕上的内容和/或动画效果。

所以我认为这不是一个真正的问题,因为它不是一个特别好的方法,可以为布局和绘图开始提供500多个图层支持的视图。 :-)

You're giving the system more work to do by layer-backing so many views. Layer-backing allows graphic acceleration (for drawing) but it adds a bit of overhead to things like layout, not to mention just creating them and putting them on screen. If used properly, it's not really much of a problem.

Typically, if you had so many "things" to manage on screen at once, you'd have one layer-backed hosting view that manages its own tree of sublayers. "But what about view-based table views?" you ask. Trickery, trickery, I say! Table views don't actually keep all the cell views they manage around; they efficiently reuse them, keeping around only enough to represent what's on screen and/or animating around.

So I'd say this isn't really a problem since it's not a particularly good approach to throw 500+ layer-backed views up for layout and drawing to begin with. :-)

更多推荐

本文发布于:2023-04-24 12:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/03fa973fed8b8787c0902636111b0620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:性能   NSView   winsLayer   performance   wantsLayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!