Should one use @property for variables that will be accessed very often, such as the position of a particle? @property creates getters and setter for a variable which adds the overhead of calling a method. In most situations this is not noticeable, but what if the property is accessed up to a million times a second (within different instances)?
Should one use @property for variables that will be accessed very often, such as
Share
You are correct that the Objective-C runtime will add a certain amount of overhead for
@propertyaccessors. However, this is the accepted way to share information between Objective-C classes. You should only consider a different approach if you have measured your application and determined that the@propertyoverhead is actually a processing bottleneck.Keep in mind that a modern processor operates in the GHz range, and something happening “a million times per second” is only in the MHz range. Chances are, your bottlenecks will be somewhere else.
If you do have a problem, you can always do your particle processing on an array of simple
Particlestructures inside of a larger Objective-CParticleCloudclass. That would allow the rest of your program to ignore the exact implementation of theParticleobjects, while removing the need for@propertyaccessors.