Javascript性能问题与多少dom节点? [英] Javascript performance problems with too many dom nodes?

查看:137
本文介绍了Javascript性能问题与多少dom节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个只是用DOM元素填满页面的ajax聊天。如果你有一个3小时的聊天,你将最终与上帝成千上万的DOM节点。

I'm currently debugging a ajax chat that just endlessly fills the page with DOM-elements. If you have a chat going for like 3 hours you will end up with god nows how many thousands of DOM-nodes.

极端 DOM使用有关的问题是什么?

What are the problems related to extreme DOM Usage?

是否可能用户界面变得完全无响应(特别是在Internet Explorer中)?

Is it possible that the UI becomes totally unresponsive (especially in Internet Explorer)?

(与此问题相关的是解决方案,如果除手动垃圾之外还有其他解决方案收集和删除dom节点。)

(And related to this question is off course the solution, If there are any other solutions other than manual garbage collection and removal of dom nodes.)

推荐答案

大多数现代浏览器应该能够处理很好的DOM树。而大多数通常不包括IE。

Most modern browser should be able to deal pretty well with huge DOM trees. And "most" usually doesn't include IE.

所以是的,您的浏览器可能无响应(因为它需要太多的RAM - >交换)或因为它的渲染器只是不知所措。

So yes, your browser can become unresponsive (because it needs too much RAM -> swapping) or because it's renderer is just overwhelmed.

标准的解决方案是删除元素,说页面上有10000行的聊天。即使是100000行也不应该是一个大问题。但是我开始对数字感到不安(数百万行)。

The standard solution is to drop elements, say after the page has 10'000 lines worth of chat. Even 100'000 lines shouldn't be a big problem. But I'd start to feel uneasy for numbers much larger than that (say millions of lines).

另一个问题是内存泄漏。即使JS使用垃圾收集,如果您在代码中出错,并保留对全局变量(或全局变量的对象引用)中删除的DOM元素的引用,那么即使页面本身只包含几个千元素。

Another problem is memory leaks. Even though JS uses garbage collection, if you make a mistake in your code and keep references to deleted DOM elements in global variables (or objects references from a global variable), you can run out of memory even though the page itself contains only a few thousand elements.

这篇关于Javascript性能问题与多少dom节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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