Click to See Complete Forum and Search --> : performance question


Count
12-19-2002, 09:51 AM
I've written a script to make snow fall and am trying to tweak the script to be able to make as many flakes fall as possible. I've tried unrolling the loop (with a combination of a few techniques), but the loop isnt long enough to make a dfference. I've tried splitting up the workload with two functions, one to update the first half of the flakes, and the other the remainder of the flakes, but that only made it worse (I guess because I was taking a multithreading approach and another setTimeout isnt another thread)

Here's where I update the position of the flake.

function move() {
for (i = (count - 1); i >= 0; i--) {
flakes[i].top = parseInt(flakes[i].top) + speeds[i];
flakes[i].left = parseInt(flakes[i].left) + wind_speed;
if (parseInt(flakes[i].top) > height || parseInt(flakes[i].left) > width || parseInt(flakes[i].left) < 0) {
reset(i);
}
}
move1_timeout = setTimeout("move()", 30);
}

The full source and working example is at http://joe.tgpr.org

Any ideas?


I should probably say that the only apparent performance change is when I change the number of flakes. I have a looping method to control the wind, and taking that out doesnt effect it much.

I notice the performance because I'm in Linux and have a performance monitor docked to my panel. My browser is Phoenix, and im guessing isn't the fastest at executing javascript (its a derivitive of Mozilla and is only at version 0.5)

Using 20 snow flakes taks about 40% of my CPU. Using 5 flakes takes about 10%. My CPU is an Athlon 1.4Ghz


Thanks
- Joe

swon
12-19-2002, 12:26 PM
Try to set the timeout of the move1_timeout function from 30 to 1.

Count
12-19-2002, 12:58 PM
Originally posted by swon
Try to set the timeout of the move1_timeout function from 30 to 1.

But that will make it execute every 1ms and make it more processor intensive, which is the opposite of what I'm looking for.

khalidali63
12-19-2002, 03:22 PM
it looks like the only thing that could possibly make a significant difference is the this value

move1_timeout = setTimeout("move()", 30);

bigget the number instead of 30 the better the performance,but you probably already have tried that..

:-)

Khalid

Count
12-19-2002, 03:43 PM
Yup, tried that :) I found 30 was the best to balance performance with visual fluidity.

Thanks