M
Mel Smith
Hi:
As my script below explains, I'm trying to speed up a search of a long
table (5600 rows x 5 columns). This table's columns are filled with text
(except with column 0 which contains a button.
Currently, my search code takes about 3 seconds to search thru 1, 2, or
3 (column 0 is the 'button' column) hiding all rows that don't contain the
searched-for text. After the search is complete, and the user wishes to see
the complete table again, this 'un-hiding' takes about 5 seconds.
But these times are for Chrome, IE7 and Safari. For FireFox, the times
are 3 times longer (i.e., worse) !!
I have two major questions:
What is there about the code below that makes FF perform so poorly ?
How can I change the code to make them *all* perform faster (even at
the expense of safety) ?
Thank you for any advice offered !
(and No, I won't show the complete web page containing this code for
another month or so -- until it is ready for 'prime time'. )
--
Mel Smith
******************************************
/* This next function is called to search for
a fragment of text in a specific column of a long table
(approx 5600 rows of 5 columns). The values in each of
the right-most columns are pure text.
This 'searching' function is fastest in Chrome, fast in
Safari, nearly as fast in IE7, and *very slow* in FF.
In fact, FF is only 1/3 as fast as Chrome and less than
1/2 as fast as IE7.
Question:
What can be changed in the following code to speed it
up ? btw, Because I know (and control) the exact structure of
the table, I have removed all error checking from the code.
What else can I do for speed only please ?
*/
/*-------------------------------*/
function tablesearch() {
var i,tr,tds,td,skipcount,searchcol ;
var term = SEARCH_INPUT.value.toLowerCase(); / user typed in this text
// vrbls rows[] and nrows are both global vrbls
// rows.length == nrows == 5564
// skip first few rows
skipCount= SKIP_ROW_COUNT ; // use a local vrbl -- this is 2 for now
searchcol = SEARCH_COLUMN ; // ditto (col 0==button) -- use col 1, 2, or
3 for now, 4 later
for (i = skipCount; i < nrows; i++) {
tr = rows; // access an individual row here
tds = tr.getElementsByTagName("td"); // maybe something could be done
here ??
td = tds[searchcol] ; // now we have the column to be searched
tr.style.display = (term == "" || doesNodeContain(td.firstChild, term)) ?
"" : "none"; // don't really know what I'm doing here
}
}
function doesNodeContain(node, term) {
if (node.nodeValue.toLowerCase().indexOf(term) >= 0) {
return true;
}
return false;
}
As my script below explains, I'm trying to speed up a search of a long
table (5600 rows x 5 columns). This table's columns are filled with text
(except with column 0 which contains a button.
Currently, my search code takes about 3 seconds to search thru 1, 2, or
3 (column 0 is the 'button' column) hiding all rows that don't contain the
searched-for text. After the search is complete, and the user wishes to see
the complete table again, this 'un-hiding' takes about 5 seconds.
But these times are for Chrome, IE7 and Safari. For FireFox, the times
are 3 times longer (i.e., worse) !!
I have two major questions:
What is there about the code below that makes FF perform so poorly ?
How can I change the code to make them *all* perform faster (even at
the expense of safety) ?
Thank you for any advice offered !
(and No, I won't show the complete web page containing this code for
another month or so -- until it is ready for 'prime time'. )
--
Mel Smith
******************************************
/* This next function is called to search for
a fragment of text in a specific column of a long table
(approx 5600 rows of 5 columns). The values in each of
the right-most columns are pure text.
This 'searching' function is fastest in Chrome, fast in
Safari, nearly as fast in IE7, and *very slow* in FF.
In fact, FF is only 1/3 as fast as Chrome and less than
1/2 as fast as IE7.
Question:
What can be changed in the following code to speed it
up ? btw, Because I know (and control) the exact structure of
the table, I have removed all error checking from the code.
What else can I do for speed only please ?
*/
/*-------------------------------*/
function tablesearch() {
var i,tr,tds,td,skipcount,searchcol ;
var term = SEARCH_INPUT.value.toLowerCase(); / user typed in this text
// vrbls rows[] and nrows are both global vrbls
// rows.length == nrows == 5564
// skip first few rows
skipCount= SKIP_ROW_COUNT ; // use a local vrbl -- this is 2 for now
searchcol = SEARCH_COLUMN ; // ditto (col 0==button) -- use col 1, 2, or
3 for now, 4 later
for (i = skipCount; i < nrows; i++) {
tr = rows; // access an individual row here
tds = tr.getElementsByTagName("td"); // maybe something could be done
here ??
td = tds[searchcol] ; // now we have the column to be searched
tr.style.display = (term == "" || doesNodeContain(td.firstChild, term)) ?
"" : "none"; // don't really know what I'm doing here
}
}
function doesNodeContain(node, term) {
if (node.nodeValue.toLowerCase().indexOf(term) >= 0) {
return true;
}
return false;
}