Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow javascript execution in IE11 until developer tools are enabled

I have a very large javascript application, which contains mostly asm.js code (it's built upon urho3d c++ engine which is them compiled into asm.js).

It runs great on most browsers (chrome, firefox, safari, edge) but is extremely slow on IE11. The thing is, it is only slow until you open developer tools. With developer tools open, IE11 becomes ~10 times faster and is almost as fast as other browsers.

Here is a minimal example that reproduces the issue:
http://test.sebbia.com/urho3d/test.html
Open the page in any working browser, the time between "Run - start" message and "Run - finish" message should be around 1-2 seconds.
Open the page in IE11 without developer tools, time should be around 35-50 seconds.
Open developer tools and reload, time should be around 2-3 seconds.

Another important note is that if I start profiling session in developer tools, performance drops like if developer tools were closed. So I can actually profile the problem. But I've spent several hours profiling and I've tried inserting log messages in big functions but I haven't found no bottleneck. All functions take roughly the same time to execute and if I insert log message in a middle of a big functions, they'll usually break into 2 similar parts. So there is no single function that is responsible for slowdown, the code execution is just slow. Bit shifts, functions calls, arithmetic operations - it seems like they all just take way too much time compared to open developer tools.

I really need to make my app work on IE11 and the fact that it works with developer tools open drives me crazy. I'm trying to find a way to make IE think that tools are open even when they are not, or achieve good performance by any other means. So my questions is how can I achieve performance equal to IE11 with developer tools open without actually manually opening the tools?

This is a very broad question so I'd like to break it down into several smaller questions:

  1. Is there a way to make IE11 think developer tools are open? Maybe there is something like x-ua-compatible meta tag I am missing?

  2. What's causing the slowdown when developer tools are closed? I've heard that console.log function calls are slow without developer tools on IE8 and 9, maybe there is a similar thing on IE11? Maybe asm.js is not optimized? If I knew what's causing this I could at least try to rewrite code to avoid this.

  3. Is there a way to open developer tools from javascript code? Maybe I could ask users to press a button on website to "make app faster". Asking them to press F12 or navigate settings seems too much.

like image 810
Alexey Avatar asked Feb 02 '18 10:02

Alexey


People also ask

Does IE 11 support JavaScript?

Internet Explorer 11 doesn't support JavaScript versions later than ES5. If you want to use the syntax and features of ECMAScript 2015 or later, or TypeScript, you have two options as described in this article. You can also combine these two techniques.

Why JavaScript is not working in Internet Explorer?

Internet Explorer When the "Internet Options" window opens, select the Security tab. On the "Security" tab, make sure the Internet zone is selected, and then click on the "Custom level..." button. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.


2 Answers

There are two workaround for this issue:

  1. to add setInterval(30000, () => {}) to your initialization function;
  2. add MutationObserver=null to the beginning of the main html

You can also reference the discussion here: https://github.com/OfficeDev/office-js/issues/521

like image 131
ginger jiang Avatar answered Oct 01 '22 18:10

ginger jiang


When the debugger is enabled, asm.js compilation will be disabled and execution will fallback to be executed as normal JS - you can see the console.logs along these lines at the start of execution.

asm.js has been disabled as the script debugger is connected. Disconnect the debugger to enable asm.js. in Edge,

asm.js type error: Disabled by debugger in Firefox,

whilst Chrome will simply not open 01_HelloWorld.js in the debugger when you attempt to.

Disabling the debugger in IE (debugger tab, socket symbol; eighth from the left), and thus enabling asm.js will allow you to have dev tools open but see the slower execution. I have a horrible feeling that the slowdown when the debugger is closed is actually just IE11's speed issues with asm.js's optimisations.

There are a lot of references to IE11 being poorly optimised for asm.js. caniuse.com goes as far as listing IE11 as not supporting asm.js at all.

https://caniuse.com/#feat=asmjs

This appears to be backed up by Microsoft themselves:

https://developer.microsoft.com/en-us/microsoft-edge/platform/status/asmjs/

There would certainly appear to be some support for it, though clearly it has a number of speed issues as demonstrated in a number of benchmarks, for instance:

https://github.com/Kukunin/asm.js-benchmark/blob/master/README.md

Which shows IE11 around 10x slower than other browsers, or:

https://www.ghacks.net/2014/11/03/massive-benchmark-highlights-asm-js-performance-of-web-browsers/

Which is based on:

https://kripken.github.io/Massive/ - You can try it for yourself.

And many others. It may simply be that the IE11 implementation of asm.js is so poor that it is considerably slower with it, than without it.

EDIT: Added Microsoft platform status link.

like image 25
Perran Mitchell Avatar answered Oct 01 '22 16:10

Perran Mitchell