For example, if I have a property index and an ivar _index, is it at all slower to use self.index, [self index] and [self setIndex:]?
For example, if I have a property index and an ivar _index , is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using the accessors impose an overhead, a method call at the very least.
That said, guesses and proofs are different things. The overhead may be great, or not. In any case, profiling the application will show where the CPU time is spent and what should be optimized. I seriously doubt using accessors over direct ivars will impact any application to the point accessors should be avoided.
Atomic and copy properties will be much much slower, these choices will have a greater impact and should be considered more carefully. Use them when appropriate.
But the answer is in profiling your app.
Edit:
Accessors have many benefits : encapsulation, code consistency between clients, derived classes and the class itself, overriding, debugging property accesses when needed, read only access checks… plenty of good reasons to pay a small performance price. All good reasons aren’t always good enough tho. 😉
If accessors become a problem, I would say an Objective-C class may not be the appropriate choice for the job. A C++ class have more opportunities to be fast : non-virtual methods, inline methods, stack based instances…