For example, in the Cocoa Framework, most of the touches methods do nothing unless you implement them. If, in all similar methods throughout my program, I call [super method:] before my custom implementation, would that ever cause realistic slowdown (hundredths of a second)?
Maybe a stupid question...But I ask since I don't know the low-level s开发者_运维问答pecifics of what a message costs.
Short answer: no.
Long answer: Messages are incredibly fast in the Obj-C runtime. The compiler optimizes the calls, the runtime optimizes the dispatch. If you're calling messages in tight loops millions of times a frame to build graphics geometry, then you'd consider the impact. Otherwise, no, especially for stuff like calling super on user input, which by definition is orders of magnitude less frequent than the system's other bookkeeping.
Exercise for the interested: Profile your app with Shark and check it out for kicks. The message dispatcher is called something like objc_msgSend
.
精彩评论