开发者

Speed comparison of Cappuccinos obj_msgSend() vs. normal JavaScript-call avaiable?

开发者 https://www.devze.com 2023-01-25 03:48 出处:网络
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.

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 comp开发者_如何学JAVAarison between this Message Sending and the normal way to execute a method in JavaScript…

someObject.someMethodToInvocate(aParameter);


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 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.


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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号