<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><blockquote type="cite" class="">On Dec 19, 2015, at 3:02 AM, Tino Heth <<a href="mailto:2th@gmx.de" class="">2th@gmx.de</a>> wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">imho the most valuable vote for mandatory self, just one comment on it </div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">1) Accessing a property, in a class, is more expensive than accessing a local variable. The above code would require three message sends and/or vtable accesses instead of one, if it were not assigning the property to a local variable. These unnecessary property accesses needlessly reduce the efficiency of the program.</div></div></blockquote></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">True for Objective-C, and might be true for Swift in many cases as well - but just because of legacy reasons:</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Correct me if I'm wrong, but I expect that simple getters have no performance penalty at all.</div></div></blockquote></div><br class=""><div class="">If a property isn’t marked final, it can be overridden by a subclass. That suggests to me that a vtable lookup is necessary at the very least. Keep in mind also that the property may be computed (and if it’s not, it might *become* a computed property at some point in the future), in which case the performance penalty could be *anything*. It could be an atomic property which takes a lock every single time it’s accessed. It could run some complex computation involving a host of other properties which themselves have unknown costs. It could even be doing something like loading something off the disk each time. Unless you have the source, you just don’t know. (And even if you *do* have the source, hunting down every single access of the property in the future won’t be fun if it becomes necessary to make the property computed in the future).</div><div class=""><br class=""></div><div class="">IMHO, best practice is to load the property once and then use the result of that, instead of spamming the getter over and over and over.</div><div class=""><br class=""></div><div class="">Charles</div><div class=""><br class=""></div></body></html>