Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Debugging error message: "A script on this page is causing Internet Explorer to run slowly"

$
0
0

Hi,

One of my users is intermittently getting a dialog in IE 8 that says:

A script on this page is causing Internet Explorer to run slowly

This problem has been reported numerous times in the MSDN forums and other places on the web.  For example:

  • http://social.msdn.microsoft.com/Forums/ie/en-US/0fdb7550-0a59-4553-a90e-1958475f2ce5/how-to-debug-a-script-on-this-page-is-causing-internet-explorer-to-run-slowly?forum=iewebdevelopment
  • http://social.msdn.microsoft.com/Forums/ie/en-US/dafffdd8-a390-4a3c-a904-867acaec298e/error-message-a-script-on-this-page-is-causing-internet-explorer-to-run-slowly-for-ie8?forum=whatforum
  • http://social.msdn.microsoft.com/Forums/ie/en-US/e9d16d2a-60e1-4d6f-8f80-0d981eab3a2e/a-script-on-this-page-is-causing-your-web-browser-to-run-slowly?forum=bingmapsajax

So, this question is a duplicate of those.  But it is an intentional duplicate, because I don't think any of those questions were answered in a way that helps a user (developer) to determine precisely what in his scenario causes the dialog to appear.  I know that based on this page:

http://support.microsoft.com/kb/175500

the dialog appears when a certain number of statements have executed since a new script begins execution (through a variety of means).  By default the number of statements is 5,000,000 but this is configurable via a registry entry.  The general prescription to this problem is a combination of:

  • Write less code.  Unfortunately, this is not always possible.
  • Use web workers. This is not an option for IE before IE 10, nor with some mobile browsers.
  • Use setTimeOut, setInterval, event handlers, etc to break the script(s) up.  This is a legitimate strategy across all browsers.

So, I understand what the problem is in general terms, and I understand what the options are to solve the problem, again in general terms.  The question is, how to determine what area(s) of the code are causing the dialog to appear for a specific user? Often this problem occurs with a very large code base (including third party libraries), so a manual review of the code base without some tooling support is not feasible.

Most browsers, including IE8 and later, have profiling tools that enable the developer to determine JavaScript CPU usage.  With the exception of IE, other browsers decide a script is long running not based on the numbers of statements executed but rather the amount of time the script spent executing.  To this end, the profilers available in (or as add ons) to the browsers can identify the percentage and usually raw time spent executing a function, both inclusively and exclusively for a function, and the results can be sorted accordingly.  IE's profiler will also give you a count of how often a function is called.  None of these profilers tell you how many statements of code within a function were executed during profiling; they tell you only how long was spent in the function and how many times the function was called.  This doesn't help with IE's slow script dialog logic, which is based on the number of statements (not time) that were executed.  There is sometimes a correlation between the time spent executing a function and the number of statements, but it is not a reliable relationship as of course different types of statements  can take very different lengths of times to execute (e.g. many native JavaScript functions are faster than calls which update the DOM; both have the same statement count but the former executes faster than the latter, making examining %/raw time not very useful).

One approach I've used that is of some value is when the slow script dialog appears, start the debugger in IE (if not already started) and select the break on next statement command in the debugger.  Then click the dialog button in the browser that allows the slow script to continue executing.  At this point, the debugger is invoked and the developer can examine the call stack to determine what is executing at the time the slow script dialog appears.  This is okay, but a very manual approach and there's no guarantee there aren't multiple scripts running that can at different times invoke the dialog.

An interesting idea I've seen suggested is to use a JavaScript code coverage tool to instrument the code base.  There are multiple JavaScript code coverage options out there, but the ease of use of a browser extension that could dynamically instrument the code seems like an ideal solution.  (Another interesting idea is to use a proxy server, for example http://siliconforks.com/jscoverage/manual.html; 'jscoverage --server --proxy', but I couldn't get this to work on virtually any website, except the the silicon forks website itself).  There's a proof of concept one available for Chrome (http://googletesting.blogspot.ca/2011/10/scriptcover-makes-javascript-coverage.html) that I think could be a great start for helping resolve the the slow script problem -- if such an extension could be made for IE.

So, to reiterate my main question is what tools/processes can one use to debug/analyze a slow script dialog appearing on a user's machine?  A subquestion would be, does anyone know of any JavaScript code analysis tools that could be repurposed to help in diagnosing the slow script dialog in IE, and that takes minimal deployment effort? Can an IE extension be written, in theory, that does the sort of code coverage as the Google' script cover extension does?

Thank you,

Notre


Viewing all articles
Browse latest Browse all 3527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>