PDA

View Full Version : Ie Dom = Slow - Why?


badg0003
07-23-2005, 02:42 PM
I've been creating a shameless hack/copy of Google's Search Suggest and everything seems to be running smoothly - except in IE, where, although it works correctly, the speed is way below that when using a Mozilla-based browser.

The demo of what I've done is Search Suggest Demo (http://apluswebcreations.dnsalias.com/SearchSuggest/).

All the scripts are viewable there, obviously, except for the one PHP script. All it does is take each keystroke input and query the database with it.

Looking forward to all your help/critcism! :)

jkd
07-23-2005, 04:39 PM
I remember Google using a setInterval() to check instead of onkeypress, so that if you type "abc" really quickly, it only sends off one request instead of 3. Makes sense to me. :)

badg0003
07-24-2005, 03:30 AM
To be honest with you, I don't think that is the major reason for the slowdown. Reason being, is that before I just dumped the results as text onto the browser screen and they both had comparable results - speedwise (Mozilla and IE), but as soon as I introduced the DOM, and created elements for each it did change things dramatically. I noticed that Google's Search Suggest is a tad slower for IE , compared to Mozilla, but its nowhere near as slow as mine.

Kor
07-25-2005, 08:11 AM
try using backward loops (starting with array's length-1 and ending with 0). It will double the loop speed as comparision with 0 is faster.

jkd
07-25-2005, 01:08 PM
try using backward loops (starting with array's length-1 and ending with 0). It will double the loop speed as comparision with 0 is faster.

That doesn't change the overall complexity of the code, though. It slightly improves the constant factor and perhaps the insignificant terms... since you're dealing with importing data and the such, I'll suggest that the import is the only significant bottleneck in the code, and not the loop construction.

I remember reading somewhere that Google Suggest actually reads in plain text, and not XML, for the values. If you could make your php output:
var response = ["one", "two", "three", ... ];

Instead of XML, then simply eval the request.responseText, you may achieve significantly faster results.

badg0003
07-25-2005, 02:58 PM
Thanks for all the help/tips guys. I'll incorporate them all in and see what sort of performace increase that I get.