铬是“appendChild”真的那么慢? [英] Is chromes "appendChild" really that slow?

查看:163
本文介绍了铬是“appendChild”真的那么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个框架,可以使用 document.createElement document.appendChild 完全生成应用程序的DOM。现在应用程序越来越大,我注意到,Chrome需要更长的时间来构建DOM作为其他浏览器。



所以,我创建了以下性能测试: p>

  window.onload = function(){
var now = new Date()。getTime(); (var i = 0; i< 10000; i ++){
document.body.appendChild(document.createElement(div));

}
setTimeout(function(){
console.log(new Date()。getTime() - now);
},0);

}

此测试的结果非常有趣:




  • Chrome 16:700 +

  • Firefox 9:560

  • IE 9:210

  • Opera 11.60:51



Chrome占用了14倍以上时间比歌剧完成。
这不仅仅是一个无意义的基准!我的应用程序真的可以感受到这种差异。



Chrome在DOM操作中的速度是否正常?
有没有办法加速?



谢谢!

解决方案

我认为这是正常的...



HTML对象操作(width& height& opacity)也是如此,重新使用CSS3。



我编程了一个幻灯片(不使用jQuery,我讨厌它),这在FF,IE,Opera,Safari,但不是Chomre。在Chrome中,这是令人难以置信的缓慢(仅在较新版本的Chrome版本中,旧版本与v12相比更快)。


I have a framework that generates the DOM of an app completely using document.createElement and document.appendChild. Now that the App gets bigger and bigger, I noticed that Chrome needs significantly longer to build the DOM as other Browsers.

So, I created the following performance test:

window.onload = function(){
    var now = new Date().getTime();
    for(var i = 0; i < 10000; i++){
        document.body.appendChild(document.createElement("div"));
    }
    setTimeout(function(){
        console.log(new Date().getTime() - now);
    },0);

}

The results of this test are very interesting:

  • Chrome 16: 700+
  • Firefox 9: 560
  • IE 9: 210
  • Opera 11.60: 51

Chrome took more than 14-times more time to complete than Opera. And that´s not just a meaningless benchmark! I really can feel this difference in my app.

Is it normal that Chrome is that slow at DOM-operations? Is there a way to speed it up?

Thanks!

解决方案

I think this is normal... .

The same goes for HTML Objects manipulation (width & height & opacity), especially if you're using CSS3.

I programmed a Slideshow (not using jQuery, i hate it) which is working smoothly... in FF, IE, Opera, Safari,... but not Chomre. In Chrome it is unbelievable slow (only in newer Chrome Versions, in old like v12 it was faster).

这篇关于铬是“appendChild”真的那么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆