>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);
>}
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