<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: performance improvement in hideCol and showCol for grid with many rows</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>2late2die on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24368</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24368</guid>
        	        	<description><![CDATA[<p>@Tony ahh nice, forgot about the while loop 🙂<br />I gave it a go (won&#39;t bore you with the numbers) but it didn&#39;t seem to improve performance noticeably. It did however reduce number of calls further so it&#39;s going in, at least for me.</p>
<p>@OlegK good catch on $($t.rows) and the "3" in my post is actually a typo, should&#39;ve been "13" columns.</p>
<p>Regarding each/for, I agree that the performance improvements are minimal but I prefer them for reduction in the number of calls made - less calls, less chances for something to go wrong 🙂</p>
<p>Now, that "trick" with calling show/hideCol once each is a nice one. I gave it a try and it seemed to have only marginally improved performance, to be fair though, pretty much all results starting with 3 (from my previous post) have fallen within margin of error so in terms of pure ms your original modification is still the only clear and definite improvement.</p>
<p>Having said that, with all the conseqent improvements the number of calls have been reduced from 4453 to 442, which consitutes a 10 fold decrease, so it&#39;s all worth while in my opinion. 🙂</p>
<p>BTW, quick question, why did you add "parseInt" in your code?</p>
</p>
<p>Anyway, it&#39;s now time to tackle setGridWidth as that&#39;s the new bottleneck in my code.</p>
]]></description>
        	        	<pubDate>Mon, 22 Aug 2011 23:11:45 +0300</pubDate>
        </item>
        <item>
        	<title>tony on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24337</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24337</guid>
        	        	<description><![CDATA[<p>Hello Oleg, 2late2die,</p>
<p>Thank you for the investigations, tests cases and recommendatins.</p>
<p>As 2late2die say the bigest speed improvements is from 1 to 2.</p>
<p>I will see how to implemet them</p>
<p>It is not neccessary to maybe to repace each, since this is not big improvements.</p>
</p>
<p>You maybe know this, but the fastest loop operator is while.</p>
<p>We can replace all the code with this one by example</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8012' value='Select Code' data-codeid='sfcode8012' /></p>
<div class='sfcode' id='sfcode8012'>
<p>var trs = $("tr",$t.grid.hDiv), trsL = trs.length,<br />trows = $($t.rows), trowsL = trows.length, j;</p>
<p>while( trsL--) {<br />&#160;&#160;&#160; trs[trsL].cells[i].style.display = show;<br />}</p>
<p>while(trowsL--) {<br />&#160;&#160;&#160; trows[trowsL].cells[i].style.display = show;<br />}</p>
</div>
<p>You can just perform tests <img class="spSmiley" style="margin:0" title="Wink" src="/blog/wp-content/forum-smileys/sf-wink.gif" alt="Wink" /></p>
</p>
<p>Regards</p></p>
]]></description>
        	        	<pubDate>Thu, 18 Aug 2011 15:26:08 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24330</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24330</guid>
        	        	<description><![CDATA[<p>Small inprovements to your code. You use <strong>trows = $($t.rows)</strong> and then <strong>trows[j].cells[i].style.display = show</strong>. Insetead of that one can <strong>$t.rows</strong><strong>[j].cells[i].style.display = show</strong>.</p>
<p>Now my opinion about the usage of <strong>for</strong> loop instead of <strong>.each</strong>. I personally use mostly <strong>for</strong>&#160;loop, but it improve the performance only a little, so in my opinion it is mosly the question of the style and not the performance problem. So I use <strong>for</strong>&#160;loop, but never change the code of other people if they use <strong>.each</strong>.</p>
<p>Now about your suggestion about the <strong>columnChooser.apply_perm</strong> code. I think the changes bring not so much performane advantages. You can try to mesure to give exact answer. My suggestion would be to rewrite the code so that it uses <em>only one call</em> of <strong>showCol</strong> and <em>only one call</em> of <strong>hideCol</strong>. The idea is to use array as the second parameter of <strong>showCol</strong>&#160;and <strong>hideCol</strong>. For exmaple:var</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1189' value='Select Code' data-codeid='sfcode1189' /></p>
<div class='sfcode' id='sfcode1189'>var columnsToShow = $(&#39;option:selected&#39;, select).map(function () {<br />&#160; &#160; &#160; &#160; return colModel[parseInt(this.value,10)].name;<br />&#160; &#160; }),<br />&#160; &#160; columnsToHide = $(&#39;option:not(:selected)&#39;, select).map(function () {<br />&#160; &#160; &#160; &#160; return colModel[parseInt(this.value,10)].name;<br />&#160; &#160; });<br />self.jqGrid(&#34;showCol&#34;, columnsToShow);<br />self.jqGrid(&#34;hideCol&#34;, columnsToHide);&#160;</div>
<p>instead of <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.jqueryui.js#L177" target="_blank">the curent code</a></p>
<p><input type='button' class='sfcodeselect' name='sfselectit4827' value='Select Code' data-codeid='sfcode4827' /></p>
<div class='sfcode' id='sfcode4827'>$(&#39;option&#39;,select).each(function(i) {<br />&#160; &#160; if (this.selected) {<br />&#160; &#160; &#160; &#160; self.jqGrid(&#34;showCol&#34;, colModel[this.value].name);<br />&#160; &#160; } else {<br />&#160; &#160; &#160; &#160; self.jqGrid(&#34;hideCol&#34;, colModel[this.value].name);<br />&#160; &#160; }<br />});&#160;</div>
<p>I don&#39;t mesure, but I think that the usage of on call of <strong>showCol</strong> and one call of <strong>hideCol</strong>&#160;should improve the performance.</p>
<p>By the way in my project which I change now for one customer I has table with about 56 columns where about 20 columns are visible at the same time. So I would suggest you to increase a little the number of columns if it maks not so many work.</p>
<p>Best regards<br />Oleg</p></p>
]]></description>
        	        	<pubDate>Thu, 18 Aug 2011 02:39:24 +0300</pubDate>
        </item>
        <item>
        	<title>2late2die on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24326</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24326</guid>
        	        	<description><![CDATA[<p>Okay, I did some better testing and here are the method, followed by results.</p>
<p>My data has 337 rows and 3 columns. For every test I reload the page and perform the same action - which is to open the column chooser and hide one column (always the same). To measure performance I used Firebug&#39;s console.profile/End() around the <strong>$(&#39;option&#39;,select).each</strong> loop in the "apply_perm" function of columnChooser.</p>
<p>I did the test five times for each of the five versions of the code and averaged the times. First version is original. Second is with Oleg&#39;s original fix -<strong> $(this.cells[i]).css("display", show);</strong>. Third one is with further simplfication via <strong>this.cells[i].style.display = show;</strong>. Fourth is with each loops replaced with for loops in the <strong>showHideCol </strong>function. Fifth and final one is where I replace the <strong>$(&#39;option&#39;,select).each</strong> part with a for loop.</p>
<ol>
<li>24173 calls, average time 451.4ms</li>
<li>4453 calls, average time 311.4ms</li>
<li>1393 calls, average time 283.4ms</li>
<li>1045 calls, average time 279ms</li>
<li>1026 calls, average time 277.2ms</li>
</ol>
<p>Total (from 1 to 5) reduction in number of calls made is almost 24 times, and timing improved by almost 40%. Obviously the biggest improvement was going from 1 to 2, however, considering the triviality of further optimizations I see no reason not to implement all of them.</p>
<p>So the code inside showHideCol, i.e. this</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8361' value='Select Code' data-codeid='sfcode8361' /></p>
<div class='sfcode' id='sfcode8361'>$(&#34;tr&#34;,$t.grid.hDiv).each(function(){<br />&#160;&#160;&#160; $(this.cells[i]).css(&#34;display&#34;, show);<br />});<br />$($t.rows).each(function(j){<br />&#160;&#160;&#160; $(this.cells[i]).css(&#34;display&#34;, show);<br />});</div>
<p>Can be replaced with this</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit5166' value='Select Code' data-codeid='sfcode5166' /></p>
<div class='sfcode' id='sfcode5166'>var trs = $(&#34;tr&#34;,$t.grid.hDiv), trsL = trs.length,<br />&#160;&#160;&#160; trows = $($t.rows), trowsL = trows.length, j;</p>
<p>for (j = 0; j &#60; trsL; j++) {<br />&#160;&#160;&#160; trs[j].cells[i].style.display = show;<br />}</p>
<p>for (j = 0; j &#60; trowsL; j++) {<br />&#160;&#160;&#160; trows[j].cells[i].style.display = show;<br />}</p>
</div>
<p>And the code in columnChooser.apply_perm</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit5833' value='Select Code' data-codeid='sfcode5833' /></p>
<div class='sfcode' id='sfcode5833'>$(&#39;option&#39;,select).each(function(i) {<br />&#160;&#160;&#160; if (this.selected) {<br />&#160;&#160;&#160; &#160;&#160;&#160; self.jqGrid(&#34;showCol&#34;, colModel[this.value].name);<br />&#160;&#160;&#160; } else {<br />&#160;&#160;&#160; &#160;&#160;&#160; self.jqGrid(&#34;hideCol&#34;, colModel[this.value].name);<br />&#160;&#160;&#160; }<br />});</div>
<p>Can be replaced with this</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1622' value='Select Code' data-codeid='sfcode1622' /></p>
<div class='sfcode' id='sfcode1622'>var os = select.find(&#39;option&#39;), ol = os.length, i;<br />for (i = 0; i &#60; ol; i++) {<br />&#160;&#160;&#160; self.jqGrid(os[i].selected ? &#39;showCol&#39; : &#39;hideCol&#39;, colModel[os[i].value].name);<br />}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;"><strong>$(&#39;option&#39;,select).each</strong></div>
]]></description>
        	        	<pubDate>Wed, 17 Aug 2011 18:09:01 +0300</pubDate>
        </item>
        <item>
        	<title>2late2die on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24316</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24316</guid>
        	        	<description><![CDATA[<p>Ha! You totally right, can&#39;t believe I missed that. <img class="wp-smiley" src="/blog/wp-includes/images/smilies/icon_smile.gif" alt=":)" /></p>
<p>I&#39;m gonna update my file right away.</p>
</p>
<p>Oh and for even further optimization the each loops should be converted into for loops, I&#39;m gonna try it out on my site and see what kinda difference that makes.</p>
]]></description>
        	        	<pubDate>Tue, 16 Aug 2011 23:47:43 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24312</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24312</guid>
        	        	<description><![CDATA[<p>I agree, but if we do optimisation we should use this:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8579' value='Select Code' data-codeid='sfcode8579' /></p>
<div class='sfcode' id='sfcode8579'>this.cells[i].style.display = show;</div>
<p>Additionally if we do optimisation of the lines we can remove unused&#160;<strong>j</strong>&#160;variable&#160;from the second&#160;<strong>.each</strong>.</p>
<p>Regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Tue, 16 Aug 2011 22:20:25 +0300</pubDate>
        </item>
        <item>
        	<title>2late2die on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24311</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24311</guid>
        	        	<description><![CDATA[<p>Hi guys,</p>
</p>
<p>This fix can be further optimized using this</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2295' value='Select Code' data-codeid='sfcode2295' /></p>
<div class='sfcode' id='sfcode2295'>$(this.cells[i])[0].style.display = show;</div>
<p>It doesn&#39;t really improve performance (at least not in any noticeable fashion) but it does reduce the number of calls made (since $.css() does a whole bunch of stuff).</p>
]]></description>
        	        	<pubDate>Tue, 16 Aug 2011 20:33:50 +0300</pubDate>
        </item>
        <item>
        	<title>tony on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24282</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24282</guid>
        	        	<description><![CDATA[<p>Thanks for this Oleg. Fixed.</p>
</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Mon, 15 Aug 2011 12:51:04 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on performance improvement in hideCol and showCol for grid with many rows</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24277</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/performance-improvement-in-hidecol-and-showcol-for-grid-with-many-rows#p24277</guid>
        	        	<description><![CDATA[<p>Hello Tony!</p>
<p>In one project I have jqGrid which show/hide some column dinamically depend on the data loaded. It allows to reduce the number of columns which are needed be displayed. All works OK, but the grid will be slow if the number of rows increase. I analysed the problem and find out that the reason are <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.base.js#L2855" target="_blank">the line 2855</a> of the grid.base.js.</p>
<p>I suggest to change the <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.base.js#L2852" target="_blank">line 2852</a></p>
<p><input type='button' class='sfcodeselect' name='sfselectit9791' value='Select Code' data-codeid='sfcode9791' /></p>
<div class='sfcode' id='sfcode9791'>$(this).children(&#34;th:eq(&#34;+i+&#34;)&#34;).css(&#34;display&#34;,show);</div>
<p>and the <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.base.js#L2855" target="_blank">line 2855</a>&#160;in both cases to the code</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8812' value='Select Code' data-codeid='sfcode8812' /></p>
<div class='sfcode' id='sfcode8812'>$(this.cells[i]).css(&#34;display&#34;, show);</div>
<p>The same technique you use already in the most places of the jqGrid code. Such changes increased the total performance dramatically.</p>
<p>Best regards<br />Oleg&#160;</p></p>
]]></description>
        	        	<pubDate>Sun, 14 Aug 2011 20:36:53 +0300</pubDate>
        </item>
</channel>
</rss>