• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is C's parameter passing more-efficient than ObjC's message passing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is C's parameter passing more-efficient than ObjC's message passing?


  • Subject: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • From: Greg Titus <email@hidden>
  • Date: Fri, 10 Feb 2006 17:20:48 -0800


On Feb 10, 2006, at 4:52 PM, David Hart wrote:

The overhead isn't so much in the parameter passing per say - but the method
invocation as a whole. With a straight C function call, you essentially just
need to branch + stack setup and tear down; with obj-c dynamic method
invocation, for example [obj foo] is really a call to objc_msg_send (or
objc_msg_sendv) with the object id, the selector and arguments as
parameters. Then objc_msg_send will locate the function address from the
selector, and branch to that + stack setup and teardown... So... Basically
it comes down to this:


Straight C:
function call is branch + stack setup and teardown/paramater passing

Objective-C:
Method invocation is function call to objc_msg_send + normal function call
overhead; so two times the function call overhead + the work objc_msg_send
does to look up the appropriate function based on the selector.


This is a bit of a simplification, but is basically it, and after having
said all of that... The overhead of a obj-c method is really a non- issue for
MOST code...


PS there are ways to speed up objc method invocation with caching of method
addresses, and i think the runtime has some caching of its own...

Actually, in the Objective-C case, after objc_msg_send has looked up the appropriate function based on the selector it simply branches to that function. When the function is done, it returns straight back into the caller, not into objc_msg_send. So there is no double function call overhead.


So your Obj-C section should read:
function call is branch + stack setup and teardown/paramater passing, plus the work objc_msg_send does to look up the appropriate function, plus one branch into that function.


The work objc_msg_send does is basically to check that the called object isn't nil, and then do a hash lookup based on the selector. It is not at all slow.

Hope this helps,
	- Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Is C's parameter passing more-efficient than ObjC's message passing?
      • From: Shaun Wexler <email@hidden>
References: 
 >Re: Is C's parameter passing more-efficient than ObjC's message passing? (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Next by Date: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Previous by thread: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Next by thread: Re: Is C's parameter passing more-efficient than ObjC's message passing?
  • Index(es):
    • Date
    • Thread