How do I identify and overcome a possible race condition when using jQuery's show() function on very large result sets?
<p>I am working on a very customized web based diff tool.  We collect network device config information before changes are made on the device, then collect the same information after config changes are made.  The user is then presented with a highly customized side-by-side diff where irrelevant results are filtered using a different css style than the relevant results.  (for example, the uptime would be different, but not relevant). </p>

<p>All this work is done on the server side, and performs well.  As one may expect there can be a large number of lines, for example "show interfaces" may easily show upwards of a 1000 lines, for both pre and post, while there may only be a few diff'ed lines to show.  What I am trying to implement is a button to hide the irrelevant lines showing only the diff'ed lines.  I use the following function to do this...</p>

<pre><code>function run_show_changed_button(command) {

    var commandWithDashes = command.replace(/\s+/gi, "-");

    var button = $(".show-changed[command='" + command + "']");
    var stage = $(button).attr("stage");
    var preRows = $("#diff-result-pre-section-" + commandWithDashes + " &gt; .diff-hide");
    var postRows = $("#diff-result-post-section-" + commandWithDashes + " &gt;  .diff-hide");

    if (stage == "all") {
        $(preRows).hide();
        $(postRows).hide();
        $(button).attr("stage", "changed");
        $(button).html("&lt;button&gt;Show All&lt;/button&gt;");
    } else {
        $(preRows).each(function() {
            $(this).css('display', 'block');
        });

        $(postRows).each(function() {
            $(this).css('display', 'block');
        });

         //$(preRows).show();
         //$(postRows).show();

         $(button).attr("stage", "all");
         $(button).html("&lt;button&gt;Show Only Changed&lt;/button&gt;");
    }
}
</code></pre>

<p>On <code>hide()</code> this function works quite well, <code>show()</code> also works well on smaller result sets, but on larger result sets the cpu load stays at about 50% (dual core system).  As far as I can tell, this load never lowers, and the function never returns.  Using chrome's inspector I can see that the selector returns quickly enough, but the problem appears to be with "recalculating style".  The system memory load doesn't appear to increasing as the function runs.</p>

<p>I'm getting to the point where I may do this on the server side, but I would like to know how to best address this problem.  I'm not married to using jQuery if there is another solution. </p>

<p>[Edited to add html sample]</p>

<p>Sample html used (with sensitive material redacted) </p>

<pre><code>&lt;div class="diff-result-post-section ui-widget wi-widget-content" id="diff-result-post-section-show-interface"&gt;
  &lt;div class="diff-result-row ordinary-row diff-hide"&gt;
    &lt;pre style="margin: 0em; padding: 1px;"&gt;Something edited out...&lt;/pre&gt;
  &lt;/div&gt;
  &lt;div class="diff-result-row ui-state-error"&gt;
    &lt;pre style="margin: 0em;"&gt;Something edited out...&lt;/pre&gt;
  &lt;/div&gt;
  &lt;div class="diff-result-row ordinary-row diff-hide"&gt;
    &lt;pre style="margin: 0em; padding: 1px;"&gt;Something edited out...&lt;/pre&gt;
  &lt;/div&gt;

    (stuff snipped)

  &lt;div class="diff-result-row ui-state-error"&gt;
    &lt;pre style="margin: 0em;"&gt;Something edited out...&lt;/pre&gt;
  &lt;/div&gt;
  &lt;div class="diff-result-row ordinary-row diff-hide"&gt;
    &lt;pre style="margin: 0em; padding: 1px;"&gt;Something edited out...&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>
