Ie, ff,chrome complain that my script is running too long, a window appears,
and the user can select to continue calculation.
Outputting something during the running script to a div with innerHTML did
not help (the output becomes visible much later).
How to prevent the complaints? (or, how to let the browsers think that there
are several shortrunning scripts instead?)
> How to prevent the complaints? (or, how to let the browsers think that there
> are several shortrunning scripts instead?)
You need to break up the computation and start each part with setTimeout.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
Speed up the calculation, obviously. The first thing to examine is your
algorithm: is there a more efficient method of accomplishing the same task?
Next examine your implementation: have you implemented this method in the most
efficient way possible?
function longCalculation () {
...
do some work during no more than a few seconds.
...
return finished;
}
(function loopUntilDone () {
if (!longCalculation()) {
//continue calculating
setTimeout(loopUntilDone, 0);
} else {
//calculation done
}
})();
Or use a web worker:
See:
http://www.whatwg.org/specs/web-workers/current-work/
http://code.google.com/apis/gears/sample.html
http://code.google.com/apis/gears/samples/hello_world_workerpool/hello_world_workerpool.html
--
Jorge.
Note that each webworker (not available in IEs) runs in a separate
thread and is automatically assigned to a different core in a multicore
CPU: this can speed up things a lot (and drain the batteries of your
laptop :-).
--
Jorge.
That makes no sense at all. If all other available cores are already
running at 100% and the one running the browser/JS engine is idling
while it waits for user input it makes much more sense to use the same
core as the existing JS engine, not a "different" one. Better to leave
the assignment of CPU cores to the OS.
Or have you just taken to making stuff up off the top of your head?
Richard.
Google is your friend.
--
Jorge.
What search term would you recommend as best able to tell me whether
"runs in a separate thread and is automatically assigned to a
different core in a multicore CPU" is the stupidest design decision
ever or a fiction that originated with you?
Richard.
> You need to break up the computation and start each part with setTimeout.
Thank you very much. In a quick test it seems to work now. And thanks for
all who replied.
With, in FF 3.0.11, a checkbox for not asking again. To restore
normality after using that, use about:config in the address bar and
restore dom.max_script_run_time (to 10).
IMHO, that could be a candidate for FAQ notes miscellanea.
I have not yet seen how to re-enable a suppressed dragon-warning.
>Outputting something during the running script to a div with innerHTML did
>not help (the output becomes visible much later).
Browser-dependent, IIRC; try Opera, Safari. There might be an option in
FF about:config; you could ask in <news:mozilla.support.firefox>
>How to prevent the complaints? (or, how to let the browsers think that there
>are several shortrunning scripts instead?)
Or, as has been said, use setTimeOut.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.