title: What is the performance of Objects/Arrays in JavaScript? (specifically for Google V8)
body: <p>Performance associated with Arrays and Objects in JavaScript (especially Google V8) would be very interesting to document.  I find no comprehensive article on this topic anywhere on the Internet.</p>
  
  <p>I understand that some Objects use classes as their underlying data structure. If there are a lot of properties, it is sometimes treated as a hash table?</p>
  
  <p>I also understand that Arrays are sometimes treated like C++ Arrays (i.e. fast random indexing, slow deletion and resizing).  And, other times, they are treated more like Objects (fast indexing, fast insertion/removal, more memory).  And, maybe sometimes they are stored as linked lists (i.e. slow random indexing, fast removal/insertion at the beginning/end)</p>
  
  <p><strong>What is the precise performance of Array/Object retrievals and manipulations in JavaScript?</strong> (specifically for Google V8)</p>
  
  <p>More specifically, what it the performance impact of:</p>
  
  <ul>
  <li>Adding a property to an Object</li>
  <li>Removing a property from an Object</li>
  <li>Indexing a property in an Object</li>
  <li>Adding an item to an Array</li>
  <li>Removing an item from an Array</li>
  <li>Indexing an item in an Array</li>
  <li>Calling Array.pop()</li>
  <li>Calling Array.push()</li>
  <li>Calling Array.shift()</li>
  <li>Calling Array.unshift()</li>
  <li>Calling Array.slice()</li>
  </ul>
  
  <p>Any articles or links for more details would be appreciated, as well.  :)</p>
  
  <p><strong>EDIT:</strong> I am really wondering how JavaScript arrays and objects work under the hood.  Also, in what <em>context</em> does the V8 engine "know" to "switch-over" to another data structure?</p>
  
  <p>For example, suppose I create an array with...</p>
  
  <pre><code>var arr = [];
  arr[10000000] = 20;
  arr.push(21);
  </code></pre>
  
  <p>What's really going on here?</p>
  
  <p>Or... what about this...???</p>
  
  <pre><code>var arr = [];
  //Add lots of items
  for(var i = 0; i &lt; 1000000; i++)
      arr[i] = Math.random();
  //Now I use it like a queue...
  for(var i = 0; i &lt; arr.length; i++)
  {
      var item = arr[i].shift();
      //Do something with item...
  }
  </code></pre>
  
  <p>For conventional arrays, the performance would be terrible; whereas, if a LinkedList was used... not so bad.</p>