如果我使用self.fooBar而不是fooBar,它会对性能产生影响吗? [英] Does it make a difference in performance if I use self.fooBar instead of fooBar?

查看:89
本文介绍了如果我使用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,它会对性能产生影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆