如果我使用self.fooBar而不是fooBar,它会对性能产生影响吗?

编程入门 行业动态 更新时间:2024-10-13 22:24:45
本文介绍了如果我使用self.fooBar而不是fooBar,它会对性能产生影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

注意:我确切知道属性是什么。这个问题与性能有关。

Note: I know exactly what a property is. This question is about performance.

使用self.fooBar进行READ访问对我来说似乎是浪费时间。不必要的Objective-C消息传递正在进行中。吸气剂通常只是沿着ivar传递,所以只要它确定没有合理的getter方法,我认为绕过这个沉重的家伙是完全没错的。

Using self.fooBar for READ access seems a waste of time for me. Unnecessary Objective-C messaging is going on. The getters typically simply pass along the ivar, so as long as it's pretty sure there will be no reasonable getter method written, I think it's perfectly fine to bypass this heavy guy.

Objective-C消息传递比直接调用慢约20倍。因此,如果有一些高性能高频代码正在使用数百个属性,那么它可能对避免不必要的Objective-c消息传递有很大帮助吗?

Objective-C messaging is about 20 times slower than direct calls. So if there is some high-performance-high-frequency code with hundreds of properties in use, maybe it does help a lot to avoid unnessessary objective-c messaging?

或者我是在浪费时间思考这个问题吗?

Or am I wasting my time thinking about this?

推荐答案

这种过早的优化应该推迟到实际通知或衡量之前(使用Instruments.app)是一个真正的问题。

This kind of premature optimization should really be postponed until you actually notice or measure (with Instruments.app) a real problem.

更多推荐

如果我使用self.fooBar而不是fooBar,它会对性能产生影响吗?

本文发布于:2023-11-29 11:25:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会对   而不是   性能   fooBar

发布评论

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

>www.elefans.com

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