/    Sign up×
Community /Pin to ProfileBookmark

Javascript running really slow in Internet Explorer

Hi everyone,

I’m not very well versed in javascript, but I’ve written an .html file that takes some user inputs and calculates an output from those inputs. The calculation involved is quite complex and uses some lengthy for loops. For example, part of the computation requires Bessel functions, and to approximate those bessel functions, I’m doing a numerical approximation up to the first 100 terms or so.

When I run the program in Google Chrome, it works just fine, although it does take a couple of seconds for the answer to be computed. Yet when I try to run it in Internet Explorer, I keep getting a message that the script is taking too long, and it asks me if I want to let it run. If I keep telling it to continue running, it will indeed finally complete.

Anybody know why this could be? If you’re interested in looking at the code, you can see it here:

[url]https://docs.google.com/leaf?id=0B-dyJuH_q8ukNjcxNjZlYTAtNjY1Zi00ZWVjLTg0YWYtMjIzNzYzZDVlZDUy&sort=name&layout=list&num=50[/url]

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdOct 07.2010 — Your link is not valid
Copy linkTweet thisAlerts:
@svidgenOct 07.2010 — I was interested to see the code, however ...

Sorry, the page (or document) you have requested is not available.[/QUOTE]

In any case, every browser I've had the pleasure to use has a point at which it will prompt the user to continue or cancel "long running" scripts. And, since IE has a notoriously slow JavaScript engine, it will be the first to report issues. See http://www.svidgen.com/images/Array%20Initialization%20Benchmarks.pdf

You might get some good advice searching around for long running javascript, but the long as short of it this: web workers are probably the "right" choice, but they're not supported in IE.

[I]However[/I], if you're up for a little challenge, you can [B]pretend[/B] that threads exist ...

Suppose you have a loop like this:
[code=html]for (var c = 0; c < max_iterations; c++) {
doSomething(someObject[i]);
}[/code]


One possible solution to avoid timeouts might be something like this:

[code=html]function loop(c_init) {
c_init = c_init || 0;

// check the time
var start = new Date();
var test_point;

for (var c = start; c < max_iterations; c++) {
// doSomething() and some_object need to be in the global scope
doSomething(some_object[i]);

// check the time
test_point = new Date();
if (test_point.getTime() - start.getTime() > 1000) {
// we've been running this loop for over 1 second.
// take a short break ... 5 milliseconds maybe?
setTimeout(loop(i + 1), 5);
break;
}
}
} // loop()

loop();[/code]


I'm not 100% sure that will work as-is. But, that's the theory -- write your loop in such a way that it can store its execution stack in the global namespace. And then occasionally break the loop, either based on a time or loop-count and set a timeout to restart it. The browser has stopped executing the script during that time, which should also reset the max-run-length clock.

Make sense?
Copy linkTweet thisAlerts:
@stojakapimpauthorOct 07.2010 — Sorry everyone. Hopefully this link will work. Not sure what the best way is to host this file. I could just paste the entire html, but that would be quite lengthy.

http://www.adrive.com/public/58529ac71b7dc062de8e120530933c5c3e40de685eee31bc7e14e32ecbe0566b.html
Copy linkTweet thisAlerts:
@svidgenOct 15.2010 — Sorry for the delay -- must've overlooked the notification for this thread.

The file didn't download correctly for me. No public or free host you can just toss it up on?

If not ... I guess I'll take a look at it if you ZIP it and upload it right in the forum here.

Is this still even an issue for you?
Copy linkTweet thisAlerts:
@stojakapimpauthorOct 15.2010 — Sorry for the delay -- must've overlooked the notification for this thread.

The file didn't download correctly for me. No public or free host you can just toss it up on?

If not ... I guess I'll take a look at it if you ZIP it and upload it right in the forum here.

Is this still even an issue for you?[/QUOTE]


Hey thanks for checking up on this. I've placed the most current html file on my ftp server at

ftp://swfscftp.ucsd.edu/users/jrenfree/sphereTS_06Oct2010.html

I've tried using the setTimeout function in my program in order to bypass the script runtime issues in Internet Explorer, but I haven't been able to utilize it correctly. I currently use it in the loop() function, but I think I also should use it in the factorial() function. I've tried, but it hasn't worked.

Any tips?

Thanks again!

-J
Copy linkTweet thisAlerts:
@svidgenNov 18.2010 — Sorry again ... if you're still working on this, I have to ask what context you need this to work in. Will this be on the public web? In a "controlled" setting? Would you be willing to rely on web workers? (not supported in IE, I think)


ADDENDUM: I realize of course, the main point is slow execution time in IE ... but ... this looks like an academic project. So, does it [B]need[/B] to work in IE?
Copy linkTweet thisAlerts:
@stojakapimpauthorNov 18.2010 — Sorry again ... if you're still working on this, I have to ask what context you need this to work in. Will this be on the public web? In a "controlled" setting? Would you be willing to rely on web workers? (not supported in IE, I think)


ADDENDUM: I realize of course, the main point is slow execution time in IE ... but ... this looks like an academic project. So, does it [B]need[/B] to work in IE?[/QUOTE]


Hey svidgen, thanks for checking up on this.

First off, I should say that I got the problem fixed. I ended up using memoization for computing the factorial and gamma functions, which cut down on enough computations that I no longer get the warning in IE. Therefore, I also don't have to use the setTimeout command, as I had expected.

But to answer your question, I need this to work on all browsers. This is not an academic problem, but a work-related one, which will go online for anybody to see.

Thanks again for the help.

-J
Copy linkTweet thisAlerts:
@svidgenNov 18.2010 — Great. Glad you got it figured out. I'd be interested to see the final product.
Copy linkTweet thisAlerts:
@stojakapimpauthorNov 18.2010 — Great. Glad you got it figured out. I'd be interested to see the final product.[/QUOTE]

If you want to check it out, you can see it here:

http://swfscdata.nmfs.noaa.gov/AST/

It's not really live yet, as there aren't any links that go to that site, so it's still somewhat being fleshed out. But the calculator itself should be functional.
×

Success!

Help @stojakapimp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...