@Tony ahh nice, forgot about the while loop 🙂
I gave it a go (won't bore you with the numbers) but it didn't seem to improve performance noticeably. It did however reduce number of calls further so it's going in, at least for me.
@OlegK good catch on $($t.rows) and the “3” in my post is actually a typo, should've been “13” columns.
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 🙂
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.
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's all worth while in my opinion. 🙂
BTW, quick question, why did you add “parseInt” in your code?
Anyway, it's now time to tackle setGridWidth as that's the new bottleneck in my code.
Okay, I did some better testing and here are the method, followed by results.
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's console.profile/End() around the $('option',select).each loop in the “apply_perm” function of columnChooser.
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's original fix – $(this.cells).css(“display”, show);. Third one is with further simplfication via this.cells.style.display = show;. Fourth is with each loops replaced with for loops in the showHideCol function. Fifth and final one is where I replace the $('option',select).each part with a for loop.
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.
So the code inside showHideCol, i.e. this
$("tr",$t.grid.hDiv).each(function(){
Ha! You totally right, can't believe I missed that. ![]()
I'm gonna update my file right away.
Oh and for even further optimization the each loops should be converted into for loops, I'm gonna try it out on my site and see what kinda difference that makes.
Hi guys,
This fix can be further optimized using this
$(this.cells)[0].style.display = show;
It doesn'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).
Oh I already saw those and have them in my code, and they do improve the performance but they're different from my modifications above.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top