Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / November 2004

Tip: Looking for answers? Try searching our database.

Performance concerns when manually manipulating the DOM

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carl - 23 Sep 2004 21:37 GMT
I have a fairly complex form that I have created that has performance issues.
After looking at a variety of possible causes I have identified one area that
definitely seems to be the leading culprit. I am programming IP SP1 with C#
and dynamically populating various elements in the underlying xml. In order
to isolate this functionality, I created a test form with a button that, when
clicked, mimics the behavior of the real form. In the xsd I created for the
form I added an unbounded complex type (called Child in the test) containing
2 elements; Name and Value. When the button is clicked code executes a loop
with 1000 iterations adding a "Child" element (including Name and Value
children) on every pass. When I click this after the form first loads (when
the underlying xml is relatively empty), the loop takes about three minutes
to process. Clicking the button a second time (to add an additional 1000
elements) takes nearly 10 minutes. Additionally while this processing is
taking place, CPU usage gets pegged on the IP process. Since my clients are
running slower processors than I, any performance lag that I am seeing is
even worse with them.

Is there something wrong with the technique I am using? I am able to
populate drop-down lists for web services identified as secondary data
sources with similar quantities in a fraction of the time. Since this is also
information being written to the DOM, wouldn't it make sense that this would
be slow as well?

I would appreciate any help or insight you might have.

Here is the main C# processing loop that I have currently implemented:

for(int i = 0; i<1000; i++)
{
        IXMLDOMNode nChild = thisXDocument.DOM.createNode(1, "Child",
"urn:www-catalysis-com:test");
        IXMLDOMNode nName = thisXDocument.DOM.createNode(1, "Name",
"urn:www-catalysis-com:test");
        IXMLDOMNode nValue = thisXDocument.DOM.createNode(1, "Value",
"urn:www-catalysis-com:orders");
        nName.text = "Loop: " + i.ToString();
        nValue.text = "Time: " + DateTime.Now.ToLongTimeString();
        nChild.appendChild(nName);
        nChild.appendChild(nValue)
        thisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children").appendChild(nChild);
}

Thanks!
Steve van Dongen [MSFT] - 24 Sep 2004 00:59 GMT
>I have a fairly complex form that I have created that has performance issues.
>After looking at a variety of possible causes I have identified one area that
[quoted text clipped - 37 lines]
>        thisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children").appendChild(nChild);
>}

Thee things to improve performance:
1.  This code doesn't have to execute on every iteration:
      tisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children")
2.  XPath searches containing // are much slower particularly on large
DOM.
3.  Build your new XML in memory and insert everything into
XDocument.DOM at once.  InfoPath will start to rerender the view after
each DOM manipulation.

IXMLDOMNode childrenNode =
  thisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children")
IXMLDOMNode tempNode = childrenNode.cloneNode(true);

for(int i = 0; i<1000; i++)
{
    // yada yada yada

    tempNode.appendChild(nChild);
}

childrenNode.parentNode.replaceChild(tempNode, childrenNode);

Regards,
Steve
--
Please post questions to the newsgroup; everyone benefits.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Greg Collins [MVP] - 24 Sep 2004 02:20 GMT
Steve's comments are very valid. It can be much faster to work with a cloned copy of your DOM when you have extensive modifications to make all at once.

One other thing you can do is use XDocument.View.DisableAutoUpdate() and EnableAutoUpdate() around the DOM changes. This may or may not be sufficient for what you are doing.

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

On Thu, 23 Sep 2004 13:37:07 -0700, "Carl"
<Carl@discussions.microsoft.com> wrote:

>I have a fairly complex form that I have created that has performance issues.
>After looking at a variety of possible causes I have identified one area that
[quoted text clipped - 37 lines]
> thisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children").appendChild(nChild);
>}

Thee things to improve performance:
1.  This code doesn't have to execute on every iteration:
      tisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children")
2.  XPath searches containing // are much slower particularly on large
DOM.
3.  Build your new XML in memory and insert everything into
XDocument.DOM at once.  InfoPath will start to rerender the view after
each DOM manipulation.

IXMLDOMNode childrenNode    thisXDocument.DOM.selectSingleNode("//tns:TEST/tns:Children")
IXMLDOMNode tempNode = childrenNode.cloneNode(true);

for(int i = 0; i<1000; i++)
{
// yada yada yada

tempNode.appendChild(nChild);
}

childrenNode.parentNode.replaceChild(tempNode, childrenNode);

Regards,
Steve
--
Please post questions to the newsgroup; everyone benefits.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Carl - 24 Sep 2004 18:49 GMT
Thanks!

Just for kicks I timed the same sample code with the various changes:

                First Pass        Second Pass
Original Code            3 min        10 min
DisableAutoUpdate            14 sec        32 sec
+Eliminate "//" in xpath        13 sec        30 sec
+Clone Node            3 sec        3 sec
Re-enable AutoUpdate         5 sec        9 sec
(just to see)

> Steve's comments are very valid. It can be much faster to work with a cloned copy of your DOM when you have extensive modifications to make all at once.
>
[quoted text clipped - 73 lines]
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Sample code subject to http://www.microsoft.com/info/cpyright.htm
Greg Collins [InfoPath MVP] - 23 Nov 2004 02:57 GMT
Thanx for sharing the perf test with us! That's some impressive performance improvement!

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

Thanks!

Just for kicks I timed the same sample code with the various changes:

First Pass Second Pass
Original Code 3 min 10 min
DisableAutoUpdate 14 sec 32 sec
+Eliminate "//" in xpath 13 sec 30 sec
+Clone Node 3 sec 3 sec
Re-enable AutoUpdate 5 sec 9 sec
(just to see)

"Greg Collins [MVP]" wrote:

> Steve's comments are very valid. It can be much faster to work with a cloned copy of your DOM when you have extensive modifications to make all at once.
>
[quoted text clipped - 69 lines]
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Sample code subject to http://www.microsoft.com/info/cpyright.htm
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.