On Oct 28, 2008, at 8:30 AM, Jerry Krinock wrote:

Although the documentation on message forwarding [1] explains that alot of stuff needs to happen, it does not say "Warning: Don't do this in performance-critical applications". So I made a test tool which forwarded a simple message with one integer argument to a class which would add it to its 'sum', an instance variable.

Sending this message 10,000 times and comparing the difference in elapsed time with a similar task that sends a similar message directly, I found that the average overhead for forwarding one message on my Intel Core 2 Duo Mac Mini was about 20 microseconds.

That would be unacceptably slow for an iterated operation in a my application, and I decided to not use message forwarding in this particular case.

Has anyone ever seen better performance for message forwarding?

Jerry Krinock

Hi Jerry,

I take it you are using forwardInvocation:? NSInvocation is heavyweight compared to a message send, as it needs to collect enough state to be able to reproduce the message and its arguments at any future date (and on any architecture, with DO).

If you don't want to store or pick apart the message, but only route it immediately to another object, you should use the forwardingTargetForSelector: method, which will be faster than forwardInvocation:.

forwardingTargetForSelector: is new to Leopard and is mentioned in the release notes at http://developer.apple.com/ReleaseNotes/Cocoa/Foundation.html

-Peter

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to