« Floating Point Benchmark: Comparing Languages | Main | Floating Point Benchmark: Ada 95 Benchmark Added »

Friday, August 5, 2005

Mozilla Firefox: JavaScript "Unresponsive" Timeouts and about:config

In the process of running the recent multi-language floating point benchmarks, I wanted to time JavaScript execution in several Web browsers with (presumably) different implementations of the language. The floating point benchmark is usually run with the iteration count set so the overall benchmark runs for about five minutes; that minimises start-up and end effects and averages out jitter and other inconsistencies in timing. (Reported results are based on at least five runs after outliers have been discarded.)

I had no difficulty running the benchmark for five minutes in the Opera browser (which also ended up delivering the best JavaScript performance), but when I tried the same test with Mozilla Firefox, I discovered that after about five seconds, the benchmark stops and the following perversely worded alert pops up: "A script on this page is causing mozilla to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?", accompanied by "OK" and "Cancel" buttons. Note that the "OK" button cancels the execution of the script, while "Cancel" says it's OK to let the script continue. If you do click "Cancel", after another five seconds the alert pops up again ad infinitum or until the JavaScript program stops running.

The reason for this appears to be that in Firefox the same thread runs the graphical user interface and JavaScript, so while a JavaScript program is executing, menus and buttons do not work, and even window repaint does not occur. A hostile Web page could, then, hang a user's browser simply by invoking a JavaScript infinite loop when the page loaded. Popping up the alert allows the user to cancel a runaway JavaScript program, whether hostile or inadvertent, without having to kill the browser. All right, given how intimately JavaScript's interaction with the browser can be, it is genuinely difficult to run it in a separate thread, and detecting whether a program is in an infinite loop is not only "difficult" (as I read on a weblog while researching this issue), it's stone impossible, and there's no question that an annoying alert beats having to manually kill and restart the browser. Still, to me, a five second timeout on script execution seems, while perhaps consonant with the attention span of the video game generation, a tad short. It certainly is irritating when you're trying to run JavaScript benchmarks.

I poked around in the various configuration panels and found no way to change it, so I put on my special X-ray Googles and discovered a whole page of configuration settings I'd never encountered before! To display it, simply type "about:config" in the Firefox URL bar et voilĂ  hundreds of settings you can twiddle to customise Firefox to your whim. Factory default settings are in normal type, and any that have been altered appear in bold. Among these is the rather stealthily named "dom.max_script_run_time" with a default of 5--this is the JavaScript timeout setting, and you can set it to any number of seconds you prefer by double clicking the item and entering the desired value. After changing this setting, you must close all Firefox windows and restart Firefox for it to take effect.

With more than 800 settings on this page, there is much to explore and the potential to eliminate some of the residual irritation due to infelicitous Firefox defaults.

Posted at August 5, 2005 01:25