注意:我确切知道属性是什么。这个问题与性能有关。
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,它会对性能产生影响吗?
发布评论