我的程序花了大部分时间在objc_msgSend。这是否意味着Objective-C有不良的性能? [英] My program is spending most of its time in objc_msgSend. Does that mean that Objective-C has bad performance?

查看:164
本文介绍了我的程序花了大部分时间在objc_msgSend。这是否意味着Objective-C有不良的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序,它有一些自定义视图,通常绘制了很多行和位图。由于性能对于应用程序有些关键,我花了大量的时间优化绘制性能。



现在,活动监视器告诉我,我的应用程序通常使用大约12% CPU和仪器(分析器)说,在 objc_msgSend 中花费了高达10%的CPU(主要用于绘制相关的系统调用)。



一方面,我很高兴这一点,因为它意味着我的绘图是大约一样快,我们的优化,在那里取得巨大的成功。另一方面,它似乎暗示,仍然使用我的CPU的唯一的事情是消息的Objective-C开销( objc_msgSend )。因此,如果我用Carbon写的应用程序,它的性能会更好。



现在我试图得出结论,Objective-C是一种语言虽然Cocoa看起来效率非常高,因为它显然比Objective-C可以发送消息更快。



所以,Objective-C真的是一种语言性能不佳?

不,Objective-C的性能并不是那么糟糕。为了证据,我引用@ bbum的关于objc_msgSend的手优化程序集的系列文章:


  1. 路线图

  2. 设置舞台

  3. 快速路径

  4. 方法查找和一些几率和结束

换句话说, objc_msgSend 很快;方法调度不是你的问题。你可以发布你的分析信息,导致你相信吗?这可能是你误读了分析,或者你做了一些在封面下很奇怪的事情。



但我保证你 objc_msgSend 不是问题。如果是,我们肯定会听说它现在。 :)


I have written an application that has a number of custom views and generally draws a lot of lines and bitmaps. Since performance is somewhat critical for the application, I spent a good amount of time optimizing draw performance.

Now, activity monitor tells me that my application is usually using about 12% CPU and Instrument (the profiler) says that a whopping 10% CPU is spent in objc_msgSend (mostly in drawing related system calls).

On the one hand, I am glad about this since it means that my drawing is about as fast as it gets and my optimizations where a huge success. On the other hand, it seems to imply that the only thing that is still using my CPU is the Objective-C overhead for messages (objc_msgSend). Hence, that if I had written the application in, say, Carbon, its performance would be drastically better.

Now I am tempted to conclude that Objective-C is a language with bad performance, even though Cocoa seems to be awfully efficient since it can apparently draw faster than Objective-C can send messages.

So, is Objective-C really a language with bad performance? What do you think about that?

解决方案

No, Objective-C's performance is not that bad. For evidence, I cite @bbum's series of articles on the hand-optimized assembly of objc_msgSend:

  1. The Roadmap
  2. Setting the Stage
  3. The Fast Path
  4. Method Lookup and some odds and ends

In other words, objc_msgSend is fast; method dispatch is not your problem. Can you post your profiling information that leads you to believe otherwise? It's possible that you're misreading the analysis, or that you're doing something really strange under the covers, etc.

But I guarantee you that objc_msgSend is not the problem. If it was, we surely would've heard about it by now. :)

这篇关于我的程序花了大部分时间在objc_msgSend。这是否意味着Objective-C有不良的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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