aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes complex algorithm crashing browsers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "complex algorithm crashing browsers" Watch "complex algorithm crashing browsers" New topic
Author

complex algorithm crashing browsers

David lorenz
Greenhorn

Joined: Feb 17, 2006
Posts: 3
I have an algorithm that builds a 2 dimensional array. It can have over 100,000 items. I've implemented this algorithm in java without problem and now have implemented it in javascript and it brings the browser to a halt or displays the message (this is a paraphrase) "a script may be cause your browser to slow down...."

Now I guess I'm not surprised but is there something I can do to maybe cleanup the code. Is there a garbage collection thing I can do?

The algorithm is a modified Levenshtein that compares paragraphs to see how many words are different.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
JavaScript will do this when a loop is normally over 10K. Is there a fix, not really. I personally would do send the data up to the server to do the processing and have to come back. Ajax may help out.

Eric
David lorenz
Greenhorn

Joined: Feb 17, 2006
Posts: 3
We are using Ajax. We may just have the server do it. Though I have just read about modified Levenshteins that use only the 2 rows of the array at a time, so perhaps the whole array need not be stored. This could reduce the sice quite a bit. 10k isn't a very big number though.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
You also need to realize that if you have this out in the public, someone may be running on a 233 with no memory. Watch how that browser handles the chugging.

There are tricks to using setTimeout to do very large loops, but it is slower and not really the best way of handling things.

Eric
David lorenz
Greenhorn

Joined: Feb 17, 2006
Posts: 3
Everything was fine as java but everyone wants no download still after all these years. Ajax has opened some doors and I hope javascript and browsers become more robust. They seem to be. We can move the processing to the server. Its just nice if you can have the client do it instead of eating up your server resources.

Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: complex algorithm crashing browsers
 
Similar Threads
How to implement the wall follower algorithm in java?
updating database cause error
Struts and browser navigation
algorithms in java
session.invalidate