问题描述
我遇到了IE7挂起访问我的Web应用程序的情况.基于George V. Reilly ,我安装了WinDbg以下载IE符号,设置Process Explorer以使用这些符号,然后使用Process资源管理器以获取挂起线程的堆栈跟踪.
I have a situation where IE7 hangs accessing my web app. Based on the excellent suggestion from George V. Reilly, I installed WinDbg to download the IE symbols, setup Process Explorer to use those symbols, and then used Process Explorer to get a stack trace for the hung thread.
我在下面粘贴了堆栈跟踪.是不是更熟悉IE内部的人对正在发生的事情有想法,或者对如何进行此工作有建议?
I have pasted the stack trace below. Does someone more familiar with the IE internals have an idea of what is happening, or a suggestion on how to progress with this?
ntkrnlpa.exe!KiUnexpectedInterrupt+0x8d
ntkrnlpa.exe!PsDereferencePrimaryToken+0x362
ntkrnlpa.exe!KiDeliverApc+0xb3
ntkrnlpa.exe!KiDispatchInterrupt+0x5a2
ntkrnlpa.exe!SeOpenObjectAuditAlarm+0x1ce
mshtml.dll!CTreePos::GetCp+0x5a
mshtml.dll!CFlowLayout::GetNestedElementCch+0x7d
mshtml.dll!CDisplay::FormattingNodeForLine+0x1d5
mshtml.dll!CFlowLayout::LineStart+0xdb
mshtml.dll!CDisplayPointer::GetLineStart+0x44
mshtml.dll!CDisplayPointer::IsAtBOL+0x4e
mshtmled.dll!CCaretTracker::PositionCaretAt+0xf9
mshtmled.dll!CCaretTracker::Init2+0x54
mshtmled.dll!CSelectionManager::SetCurrentTracker+0x26
mshtmled.dll!CSelectionManager::CreateTrackerForContext+0x1c0
mshtmled.dll!CSelectionManager::SetEditContext+0x8b
mshtmled.dll!CSelectionManager::SetEditContextFromElement+0x2ed
mshtmled.dll!CSelectionManager::EnsureEditContextClick+0x343
mshtmled.dll!CSelectionManager::HandleEvent+0xb9
mshtmled.dll!CHTMLEditor::PostHandleEvent+0x89
mshtml.dll!CDoc::HandleSelectionMessage+0x1e0
mshtml.dll!CDoc::PumpMessage+0xb69
mshtml.dll!CDoc::OnMouseMessage+0x3d7
mshtml.dll!CDoc::OnWindowMessage+0x748
mshtml.dll!CServer::WndProc+0x78
USER32.dll!InternalCallWinProc+0x28
USER32.dll!UserCallWinProcCheckWow+0x150
USER32.dll!CallWindowProcAorW+0x98
USER32.dll!CallWindowProcW+0x1b
IEDevToolbar.dll!DllUnregisterServer+0xe21d
USER32.dll!InternalCallWinProc+0x28
USER32.dll!UserCallWinProcCheckWow+0x150
USER32.dll!DispatchMessageWorker+0x306
USER32.dll!DispatchMessageW+0xf
IEFRAME.dll!CTabWindow::_TabWindowThreadProc+0x189
kernel32.dll!BaseThreadStart+0x37
推荐答案
基于堆栈跟踪,它位于更改DOM的中间.正如您以前的文章中所评论的那样,在DOM上进行读写操作时(与Firefox和Chrome相比,IE效率极低).
Based on the stack trace, it is in the middle of altering the DOM. As commented on your previous post, IE is extremely inefficient when doing both reads and writes on the DOM (when compared to Firefox and Chrome.)
可以通过以下方式减少和优化DOM的读取和写入来解决性能问题:
The performance problems can be tackled by reducing and optimize both the reading and the writing of the DOM by:
- 尽可能使用简单的DOM属性和方法(
Document.getElementById
,DomElement.parentNode
,DomElement.childNodes[]
,DomElement.nextSibling
等)导航DOM,而不是XPATH(CSS)选择器方法(DomElement.querySelector
)- 这是因为
querySelector
在IE下的行为为O(N),其中N是整个DOM 的大小-也就是说,您将支付以下费用:即使您在没有子节点的叶节点上调用querySelector
,也会遍历整个DOM! - 如果您触发DOM相当子集中的每个元素的一个或多个
querySelector
调用,那么您实际上要付出O(N ^ 2)的罚金 - 请注意,YUI的
YAHOO.util.Selector.query
,原型的element.down
,element.up
,element.select
都在内部使用了querySelector
调用
- 这是因为
- navigating the DOM using simple DOM properties and methods whenever possible (
Document.getElementById
,DomElement.parentNode
,DomElement.childNodes[]
,DomElement.nextSibling
, etc.) instead of the XPATH (CSS) selector methods (DomElement.querySelector
)- this is because
querySelector
behaves O(N) under IE, where N is the size of the entire DOM - that is, you will pay the penalty of traversing the entire DOM even if you callquerySelector
on a leaf node that has no children! - if you trigger one or more
querySelector
calls for each element in a considerable subset of the DOM, you are essentially paying O(N^2) penalty - note that YUI's
YAHOO.util.Selector.query
, Prototype'selement.down
,element.up
,element.select
all use thequerySelector
call internally
- this is because
- 一次只提供很少的信息;强制用户点击(例如,展开链接等),以便您进行其他处理/修改
- present as little information at a time; force the user to click (e.g. on expand links etc.) in order for you to proceed with additional processing/modifications
鉴于您正在使用YUI,就选项1而言,您可能没有太多的自由度,并且我可以想象到,选项3几乎对您来说不是一个选项.不幸的是,这留下了选项2.
Given that you are using YUI you may not have a lot of latitude as far as option 1 goes, and I can imagine that option 3 is almost certainly a non-option for you. Which unfortunately leaves option 2.
这篇关于IE挂有100%CPU/获得了堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!