title: jQuery - Improving selector performance when processing XML
body: <p>I am processing an XML file that has very slow performance when selecting Nodes with XPath style selectors.</p>
  
  <p>Here is part of the code that runs particularily slow</p>
  
  <pre><code>for (i=0;i&lt;lanes.length;i++)
      htmlContents += GetLaneInfo($(this).find("Lane[num='"+lanes[i]+"']").attr('avg'));
  </code></pre>
  
  <p>I believe the slowest part of this code is the <code>Lane[num=X]</code> selector, how can I improve the performance of this? Can I cache <code>$(this).find("Lanes")</code> and then search through them later on?</p>
  
  <p>XML Sample:</p>
  
  <pre><code>&lt;Data time="10:50"&gt;
      &lt;Lane num="102" avg="2.0"/&gt;
      &lt;Lane num="103" avg="2.0"/&gt;
      &lt;Lane num="104" avg="2.0"/&gt;
      &lt;Lane num="112" avg="2.0"/&gt;
      &lt;Lane num="113" avg="2.0"/&gt;
      &lt;Lane num="114" avg="2.0"/&gt;
      &lt;Lane num="115" avg="2.0"/&gt;
      &lt;Lane num="122" avg="0.9"/&gt;
      &lt;Lane num="123" avg="1.0"/&gt;
      &lt;Lane num="124" avg="1.0"/&gt;
      &lt;Lane num="132" avg="0.7"/&gt;
      &lt;Lane num="134" avg="0.7"/&gt;
      &lt;Lane num="142" avg="0.8"/&gt;
      &lt;Lane num="153" avg="0.4"/&gt;
      &lt;Lane num="154" avg="0.6"/&gt;
  &lt;/Data&gt;
  </code></pre>