Cappuccinos obj_msgSend() 与普通 JavaScript 调用的速度比较?
如您所知,Cappuccino 实现了 Objective-C / Smalltalk 的调度机制,通过名为 objj_msgSend 的特殊方法向对象发送消息(~调用它们的方法)。
[someObject someMethodToInvocate: aParameter];
显然,这会带来一些开销,从而导致速度损失。我想知道是否有人可以提供此消息发送和在 JavaScript 中执行方法的正常方式之间的速度比较......
someObject.someMethodToInvocate(aParameter);
As you know Cappuccino implements the dispatch mechanism of Objective-C / Smalltalk to send messages to objects (~call their methods) in a special method called objj_msgSend.
[someObject someMethodToInvocate: aParameter];
Obviously this introduces some overhead and therefor speed-loss. I'd like to know if somebody can provide a speed comparison between this Message Sending and the normal way to execute a method in JavaScript…
someObject.someMethodToInvocate(aParameter);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的评论中,您说您想知道卡布奇诺应用程序中的“一般情况”。在这种情况下,测试很简单:运行任何 Cappuccino 应用程序,例如 GitHub Issues,然后自行判断是否慢与否。尝试在主表中滚动,选择一些条目等等。这将告诉您卡布奇诺“总体上”是快还是慢,因为 objj_msgSend 广泛用于您可以在此类应用程序中想到的任何用例。
如果您实际上正在考虑更具体的事情,请注意 Cappuccino 并没有强制您使用消息传递。就像在 Objective-C 中一样,当你需要做一些性能密集型的事情时,你总是可以“全力以赴”——在本例中是纯 JavaScript。如果您有一个紧密的循环,并且不需要 objj_msgSend 提供的附加功能,只需直接调用函数即可。 Objective-J 不会介意。
In your comments you say you're wondering 'in general' in the context of Cappuccino applications. In that case the test is easy: run any Cappuccino application, such as GitHub Issues, and judge for yourself if its slow or not. Try scrolling in the main table, select a few entries and so on. That'll tell you if Cappuccino is fast or slow 'in general' as objj_msgSend is used extensively in any use case you can think of in an application like this.
If you're actually thinking of something more specific after all, note that nothing about Cappuccino forces you to use message passing. Just like in Objective-C you can always 'drop down to the metal' - pure JavaScript in this case - when you need to do something more performance intensive. If you have a tight loop, and you don't require the additional functionality provided by objj_msgSend, simply call functions directly. Objective-J won't mind.
objj_msgSend
用于我对纯方法调用的简单测试,该调用比直接调用慢约 2-2.5 倍。考虑到它所提供的高级功能,这实际上相当不错。
objj_msgSend
is for my simple tests of pure method calling about 2–2.5 times slower than a direct call.That is actually quite good, given the advanced features it makes possible.
这已经晚了两年,但这是一个稍微无效的问题(绝不是说这使它成为一个坏问题)。当您假设 objj_msgSend 是 Smalltalk/Obj-C/Obj-J 特定功能时,质疑 objj_msgSend 的速度确实没有任何意义。
Javascript 一直都有这种能力。
查找: call() 和 apply() 方法...(快速谷歌搜索将显示这样的文章 -> http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/ )
这是jQuery/Prototype/etc 也有同样的问题...,它们都很好、很花哨、很有用。但它们伤害了开发社区,因为每个人都依赖这些框架,而不是学习使任何语言变得有用的核心语言功能。
帮自己和开发社区一个忙,学习您的语言,而不是框架。如果你知道你使用的语言,你使用的框架是无关紧要的,使用它们或者只是自己构建它们,因为那时你应该能够做到。
希望这对您有所帮助,而不是居高临下,这不是我的意图。 :)
This is coming two years too late, but this is a slightly invalid question (in no way saying that makes it a bad question). There is really no point questioning the speed of objj_msgSend, not when you are assuming that it is a Smalltalk/Obj-C/Obj-J specific feature.
Javascript has ALWAYS had this ability.
Lookup: the call() AND apply() methods... (a quick google search will bring up articles like this -> http://vikasrao.wordpress.com/2011/06/09/javascripts-call-and-apply-methods/ )
It is the same issue with jQuery/Prototype/etc..., they are all fine and dandy and useful. But they hurt the development community because everyone relies on these frameworks instead of learning the core language features that make any language useful.
Do yourself and the development community a favor and LEARN YOUR LANGUAGES, NOT FRAMEWORKS. If you know the languages you use, the frameworks you use are irrelevant, use them or just build them yourself, because at that point you should be able to.
Hope that came off as helpful and not condescending, thats not my intention. :)