Ticket #7504 (closed bug: invalid)
Very slow selector in jQuery > 1.4.2
|Reported by:||ktecho@…||Owned by:|
I was using jQuery 1.4.2 to develop a very big and complex form where I must show and hide some fields between 3000+ elements. I have used previous versions as well, but 1.4.2 is the latest one to work ok. When 1.4.3 was released, I was very excited with the speed improvements shown in the jquery blog, as iterating through 3000 fields is sometimes a bit slow, but when I tried 1.4.3 I realized that it's a lot slower (some order of magnitude, or like 5 - 7 times slower).
The browser I have to use (it's used in the client PCs) is IE7, and with 1.4.3 (and 1.4.4) IE7 show 4 or 5 times the message 'Script is taking too much time, do you want to cancel it?'
I'm going to describe how the elements are and how I'm iterating them:
This is a common element:
<tr tab="ta_1" dim="en_A,re_V,se_2,tsk" id_col="AVNSEG_SAR_MEMBER" style="display: none;"> [...] A lot of table info... links and a form element (textarea, input, etc.) </tr>
This is an example selector used to show and hide groups of elements:
var tabCache = $(tabCacheGet(1));
$(tabCache).filter( '[dim=en_A][dim*=re_V],' + '[dim=en_G][dim*=re_G],' + '[dim=en_T][dim*=re_G],' + '[dim=en_G][dim*=re_I]' ).filter(selectorSeccionesActivadas).filter(':not([dim*=adv])').show();
The first filter parameter (tab="ta_1") is something like a super-group of elements that I cache to improve speed (it really saves time after the first search) using the function tabCacheGet(1). Once I have the supergroup of elements, I do the rest of the filtering with "filter" and the different 'dim' literals.
If you want for me to test some patch or something, I can do it, as speed difference is so big that I don't need a profiler or anything.
Thanks a lot.