简体   繁体   English

为什么在此javascript执行中IE8比IE9快?

[英]Why IE8 is faster than IE9 on this javascript execution?

Like in the title I have quite unusual problem. 就像标题一样,我遇到了非常不寻常的问题。 I'm working on web app which has a view which is rendered quite fast in IE8 and much slower in IE9. 我正在使用Web应用程序,该应用程序的视图在IE8中呈现得非常快,而在IE9中呈现得慢得多。

Profiler says that the most time consuming function is this: Profiler说,最耗时的功能是:

function handleTree(request, rootTagName) {
  var text = request.responseText;
  var startIndex = text.indexOf("<" + rootTagName + ">");
  var endIndex = text.indexOf("</" + rootTagName + ">");
  var newHtml = text.substring(startIndex + rootTagName.length + 2, endIndex);
  var treeContainer = getCachedElement("tree");
  treeContainer.innerHTML = newHtml;
  AjaxRequestEnd();

}

I checked in debugger and only in the line 我在调试器中检查了并且只在行中

treeContainer.innerHTML = newHtml;

execution stops for a while. 执行停止一会儿。 The treeContainer is an empty div element. treeContainer是一个空的div元素。 The inserted html is pretty big so I suppose it's because of constructing the dom tree. 插入的html很大,所以我想这是因为构建了dom树。

But still, before IE even calls this function, it's hanging for a few seconds. 但是,即使在IE甚至没有调用此函数之前,它都会挂起几秒钟。 As I mentioned, on IE8 everything works faster. 正如我提到的,在IE8上,所有功能都可以更快地运行。 Any ideas? 有任何想法吗?

Edit: I know I didn't provide too detailed description but I don't have any ideas what else can be important in this context. 编辑:我知道我没有提供太详细的描述,但是我没有任何想法在这种情况下还有什么重要的。

It might be the string manipulation you are doing before assigning the innerHTML property. 可能是在分配innerHTML属性之前正在执行的字符串操作。 A regular expression might speeds things up: 正则表达式可以加快速度:

function handleTree(request, rootTagName) {
  var treeContainer = getCachedElement("tree");

  treeContainer.style.display = "none";
  treeContainer.innerHTML = request.responseText
    .replace(new RegExp("<" + rootTagName + ">(.+?)</" + rootTagName + ">"), "$1");
  treeContainer.style.display = "";

  AjaxRequestEnd();
}

If that doesn't help, you are probably running into a performance issue in IE9 when it parses the HTML. 如果这样做没有帮助,则可能是IE9在解析HTML时遇到性能问题。

This other Stack Overflow question might be worth a read too: 这个其他堆栈溢出问题可能也值得一读:

Bad performance IE using documentFragment 使用documentFragment的IE性能不佳

The treeContainer , if visible and attached to the document, might be treated differently. 如果treeContainer可见并附加到文档中,则可能会有所不同。 Try setting its display style to "none", then set the innerHTML, then set the display back to an empty string to see if that makes a difference. 尝试将其显示样式设置为“ none”,然后设置innerHTML,然后将显示设置回空字符串以查看是否有区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM