Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : Using innerXml and outerXml on a xmlDataDocument leaks cpu-resourc


Henrik K
8/24/2004 12:17:01 AM
Selecting element nodes from a xmlDataDocument using the childNodes
collection or by using selectSingleNode and then reading innerXml or outerXml
leaks cpu-resources.

A trivial example showing this behaviour is included below.
Running this example increases the cpu-load gradually and reaches 100%
within a minute or two.

The problem exists with innerXml as well as outerXml operations.
Using a xmlDocument instead of a xmlDataDocument does not show this behaviour.



Imports System.Xml

Public Class Form1
Inherits System.Windows.Forms.Form

Private xmlData As New XmlDataDocument
Private WithEvents timer As New Windows.Forms.Timer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
xmlData.LoadXml("<root><element/></root>")
timer.Interval = 250
timer.Start()
End Sub

Private Sub timer_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles timer.Tick
Dim y As String

For i As Integer = 1 To 150 'Actual loop count may be adjusted to
your computer
y = xmlData.DocumentElement.ChildNodes(0).OuterXml
Next
End Sub
End Class


Regards

v-kevy NO[at]SPAM online.microsoft.com
8/24/2004 9:36:18 AM
Hi Henrik,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
v-kevy NO[at]SPAM online.microsoft.com
9/2/2004 8:48:43 AM
Hi Henrik,

The message loop itself is taking almost twice what the XML portion
consumes. We can defer the problem substantially by adding the following
beginning and end of the timer_Tick event:

================
timer.Enabled = False

...

timer.Enabled = True
================

Also, if I bump the timer interval to 500 msec from 250, I never came close
to pegging the CPU.

Note that I haven't changed anything in the System.XML code. Certainly the
XMLDataDocument methods seem to be somewhat more processor-intensive than
the XMLDocument methods, but the internal message loop associated with the
timer events seems to account for the bulk of the CPU usage.

We note there are some CPU issues with the XMLDataDocument Class but the
bulk of the performance difference can be attributed to the messages passed
between the timer and the form. The issue has been escalated to our
developers and we are waiting for feedback on this. We will pass the
feedback along as it becomes available.

Please test the changes above and see if it helps.
Have a good one.

Ken
==============
"This posting is provided "AS IS" with no warranties, and confers no
rights."

AddThis Social Bookmark Button