I am observed behaviour similar to 2003 topic ".NET & XML -
SelectNode() is wasting time :-(".
I have big Windows forms application written in C# on .NET 1.1. The
application becomes slower as it runs. I tend to attribute it to
memory. Profiler shows SelectNodes and SelectSingleNode as functions
that become considerably slower over time. Initially it takes ~0.001
sec, and these calls become ~0.3 seconds.
App uses XML DOM as cache, and it is not large, probaly ~10K. As app
runs it does not increase, so slowness is not attributed to the growing
size of XML.
Profiling shows, that Select... functions slow down because of calls to
CreateNavigator, that calls DocumentXPathNavigator, that calls
CreateAttribute. (I looked in the rotor code, it is namespace for xml).
That CreateAttribute call is very slow, maybe because of memory
problems.
I partially worked around by caching XPath navigator, but it does not
sound right to create cache of XPathNavigators...
I cannot switch to XPathDocument, because XML is writable, and I need
flexibility of DOM. What I see does not seem like DOM limitation, but
rather .NET bug or at least glitch: in rotor code that attribute is
read-only, and it is not added to the tree.
I created a smaller single threaded console test with some memory
poluting (string concatination), and it does show slowness from time to
time, but not always.
My UI app is multithreaded, so it is possible that DOM is accessed by
2-3 threads. Could it be the problem? Is XmlDocument locked during
CreateAttribute call?
I appreciate any help or hints!
Thank you
Dima