JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 24th, 2004, 10:24 AM
yisraelharris yisraelharris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 14 yisraelharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
setTimeout becomes very slow

I have written a short javascript program which draws an array of orbits, creating one large circle. It uses setTimeout heavily.

The program runs correctly, but becomes increasingly slower as it runs. I have no idea why. The url is

http://www.geocities.com/finewebsit...ularGroup3.html

My hat's off to anyone who can get this program running without the slowdown.

I have tried many, many things to fix this and none of them worked. It's a very short program, so if you think you have the solution, why not try it yourself before posting it here.

Note that all the code after the closing html tag is added on by geocities.
Note also that the same problem occurred when I ran it locally on my machine before I uploaded it to geocities.

Reply With Quote
  #2  
Old January 26th, 2004, 04:56 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
If i was you I'd echo the value that increases the timeout value - I would think that's where your problem lies - it is probably being increased incorrectly.

Note for others - your browser will almost come to a halt when viewing the page.... my Moz FB did anyway.

Reply With Quote
  #3  
Old January 26th, 2004, 05:10 AM
yisraelharris yisraelharris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 14 yisraelharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you for your reply.

I don't think there is a problem. The values are "blue", 20, etc. Nothing wrong with that.

More food for thought: if I set the display to "none" (and put in a window.status statement to ensure that the program continues running), then the delay disappears!

I'm beginning to think that the browser simply collapses from the strain of putting up 7,000 objects through setTimeout.

Reply With Quote
  #4  
Old January 26th, 2004, 07:03 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Um, yeah, 7,000 objects can a browser screw.

Reply With Quote
  #5  
Old January 26th, 2004, 02:41 PM
yisraelharris yisraelharris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 14 yisraelharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
On the other hand, it's not the objects in and of themselves, because if I set the style.display to "none", then the slowdown disappears! So it's more subtle, methinks.

Reply With Quote
  #6  
Old January 26th, 2004, 03:10 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Maybe it's the rendering of the objects, which would be done client-side. When the display is set to none, the objects don't have to be rendered and so there's not as much local memory dedicated to displaying the page.

Reply With Quote
  #7  
Old January 26th, 2004, 03:33 PM
yisraelharris yisraelharris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 14 yisraelharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Could you clarify what "rendering" means?

Thank you.

Reply With Quote
  #8  
Old January 26th, 2004, 03:54 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I'm no expert on the ways browsers work, but what I'm proposing is that if a browser actually has to render (draw) an object on the screen, it probably takes longer than if the browser just has to keep track of the fact that the object exists. So if you're tracking 7000 objects but not drawing them, there's less load on the browser and thus less of a hit on the memory. Setting the display property to "none" prevents the browser from having to draw the objects. This would seem to account for why the script runs without taxing the browser if you don't draw the objects.

It might be interesting to run some tests. For example, add a modulus in your loop that sets the display to inline (or whatever) for every thousandth iteration. Then for every hundredth. Then for every tenth. Then for every fifth. I'll bet each of these tests will become progressively slower because each one is having to render more objects. Just a theory.

Reply With Quote
  #9  
Old January 26th, 2004, 04:01 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Just thought of another way you can monitor the speed. Within your loop, add "window.status=batchNumber;" so that you can watch what iteration you're on.

I did this, set the display to none (across the board) and noticed that the script screams through the first 70 or 80 iterations (as opposed to slowing way down by 30 or 40 when displaying the arcs) and then begins to slow down gradually to a crawl. This would seem to indicate that while the rendering does hit the browser harder than when you don't render the arcs, this script's destined to bomb simply by virtue of the size of its loop and (presumably) tracking times, etc., for each iteration.

Reply With Quote
  #10  
Old January 27th, 2004, 02:07 AM
yisraelharris yisraelharris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 14 yisraelharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Interesting.

I too tried setting the display to none and using window.status to monitor progress, and there was no slowdown whatsoever.

I got a very nice solution in another forum: increase the setTimeout from 1 to 200. Naturally, the program is considerably slower, but its speed remains constant throughout. (Tortoise and hare?) I also decreased the number of objects from 7000 to 5000. Combined, the program completes in under 2 minutes.

Reply With Quote
  #11  
Old January 27th, 2004, 08:58 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Excellent. Thanks for the followup.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > setTimeout becomes very slow


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway