Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome performance: "standard" property names vs. non-standard
    text
    copied!<p>So this is an interesting one... While I was testing the performance of setAttribute vs. normal property set on an element, I found an odd behavior, which I then tested on regular objects and... It's still odd!</p> <p>So if you have an object <code>A = {}</code>, and you set its property like <code>A['abc_def'] = 1</code>, or <code>A.abc_def = 1</code>, they are basically the same. But then if you do <code>A['abc-def']</code> = 1 or <code>A['123-def']</code> = 1 then you are in trouble. It goes wayyy slower. I set up a test here: <a href="http://jsfiddle.net/naPYL/1/" rel="nofollow">http://jsfiddle.net/naPYL/1/</a>. They all work the same on all browsers except chrome. The funny thing is that for "abc_def" property, chrome is actually much faster than Firefox and IE, as I expected. But for "abc-def" it's at least twice as slow.</p> <p>So what happens here basically (at least from my tests) is that when using "correct" syntax for properties (legal C syntax, which you can use with dot properties) - It's fast, but when you use syntax that requires using brackets (a[...]) then you're in trouble.</p> <p>I tried to imagine what implementation detail would distinguish in such a way between the two modes, and couldn't. Because as I think of it, if you do support those non-standard names, you are probably translating all names to the same mechanics, and the rest is just syntax which is compiled into that mechanic. So . syntax and [] should be all the same after compilation. But obviously something is going the other way around here...</p> <p>Without looking at V8's source code, could anyone think of a really satisfying answer? (Think of it as an exercise :-))</p> <p><a href="http://jsperf.com/property-dash-parformance" rel="nofollow">Here's also a quick jsperf.com example</a></p> <p>Thanks to NDM for the jsperf example!</p> <blockquote> <p><strong>Edit:</strong></p> <p>To clarify, of course I want also a concrete answer from the real code (which I already found) or to be more precise - the reason behind that specific implementation. That is one of the reasons I asked you to look at it "as an exercise", to look behind the technical implementation and try to find the reason.</p> <p>But I also wanted to see how other people's minds work in cases like these. This may sound "vague" to some of you - but it is very useful to try and think like other people from time to time, or take their point of view. It enhances your own ways of thinking.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload