On 12/31/10, Joe <thewast...@gmail.com> wrote: >> Caching a property lookup is usually not really worth it*. Best >> consideration for doing it anyways is clean code. But don't do it for >> speed. > > In terms of data access, object property lookup *is* slower than using > a local variable. Peter's right that for the most part it doesn't > matter and that clean code is the important thing,
Yes. And a clean interface is a good thing, too. When hidden members are wanted, they can be kept hidden in scope (on a VariableEnvironment), and not as object properties that begin or end with underscores or dollar signs. Balaz's (sp?) cleaned up version of a test I made shows that implementations have been improving leaps and bounds WRT closure performance. <https://spreadsheets.google.com/pub?key=0AkXKo_3bj2oXdDRfUFlSWFJxdlJvbDJPWl85dlFqREE&hl=en&single=true&gid=0&output=html> If the outlier result from IE9 beta is discarded, assigning to an identifier in a closure (closureAssign) is actually faster than assigning to an object property. This evidence pretty much does away with the argument that closures are slow and should be avoided. There is also a test for closureRead but I did not make a test for objectPropertyRead to compare against. However, based on the results from assigning, and based on the overall speed from closureRead, major performance differences from accessing an object property are not expected. but if you have an > object property that is getting hit within a loop and has the > potential of being used a lot, using an alias will be better for > performance. I guess the rule of thumb is to write for clarity, and > only worry about doing micro-optimizations when you notice performance > issues. That's true, too and especially true when the property is a DOM object, which it might actually be a getter and not a cached property. -- Garrett -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com