...

View Full Version : Javascript Efficiency Question



pneeko
08-30-2010, 07:31 PM
Hi,

In this scrollable list table here (http://96.57.154.180), if you do a partial lookup, or type and submit "all" a big list gets generated and for some reason it works really fast in chrome and firefox, but works really slow in Internet Explorer.

If you just take a glimpse, because it's all written in amateur javascript, do you notice anything terribly inefficient that I could change to maybe speed up the onmousemove refresh? What do you think in general about this approach to displaying large quantities of data at once?

Old Pedant
08-30-2010, 08:23 PM
http://96.57.154.180/ezgen/
Service Temporarily Unavailable

Let us know when it's working again.

FWIW, MSIE *is* much slower in many many things than FF or Chrome.

rnd me
08-30-2010, 09:07 PM
for (var j = 0; j < searchTitle.length; j++) {

could be


for (var j = 0, mx= searchTitle.length; j <mx; j++) {


should boost ie about 30% compared to an unbuffered length cap.
i don't know how much it will help your app since i don't debug IE for free, but it tends to...


also, String(i) + String(5) could be slightly faster by using i+""+5, since it avoids extra function calls.

that's what popped out at me at a glance, you can have your money back if it doesn't help ;)

pneeko
08-30-2010, 09:10 PM
I understand that Chrome and FF run javascript more smoothly in general.

I was however able to gain an improvement by consolidating variable declarations inside the script tag at the top of the body, rather than having them declared inside of functions or events located more in the center, but it seems like it can run faster without too much overhauling.

pneeko
09-01-2010, 08:15 PM
Sorry for recirculating an old thread, but I put it back up again, so an inquiry will generate the scrollable list table I would just like to know if there's something I can do to tweak my code in IE to get more refreshes on events, particularly the document.mousemove event. I don't have errors at the moment, just possibly a design flaw.

I'm trying to display thousands of pieces of selectable data with one page load without a lot of overhead. Is there a more practical way of doing this without browser addons/modules?

It seems inconvenient to have to click on "display 1-20" or "50-60" or "120-140", or waiting for the server to respond with Ajax (in the few applications I've seen) when instead you can see all 5000 in one shot.

Old Pedant
09-01-2010, 08:18 PM
How about this?

Show the first 100 immediately.

Then, behind the scenes, use AJAX to load the other 4900. By the time the user has stared at the page for a few seconds and realizes he/she really wants to see 1733, it will be there.

pneeko
09-01-2010, 08:35 PM
How about this?

Show the first 100 immediately.

Then, behind the scenes, use AJAX to load the other 4900. By the time the user has stared at the page for a few seconds and realizes he/she really wants to see 1733, it will be there.

I would gladly try that, but even with just 200 rows of data, the scrolling in IE is still slow.

The data for each column is loaded into an array of literals, and a fixed table of divs. Each time the scroll slider goes up or down, the divs get updated to the correct position in the literal array using a for loop.

data = new Array(9);

data = ["data1", "data2", ...];

div[3] = new div (gets instantiated in the js file);
data1
data2
data3 div 1
data4 div 2
data5 div 3
data6
data7
data8
data9
...


scroll down and all that happens is


data1
data2
data3
data4
data5
data6 div1
data7 div2
data8 div3
data9
...

Old Pedant
09-01-2010, 09:03 PM
Got me, then. Something you are doing is just busting IE's bubble. Hard to believe it can't scroll 200 items fast enough.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum