Faster way to reconstruct XmlDocument

Z

Zeng

Hello,

I have profiled my code, and the current performance bottleneck is this
routine. It gets called 7400 times to do some intensive calculations when a
user uses the feature. The xmlText parameter will be used to pass in a xml
document text stored in db, the text contents (about 200 of these guys
total) are stored in a cached static variable. My web app must be
thread-safe, so I cannot create and cache 200 XmlDocument objects because
each thread will do differently to the object it uses including modifying
its content.

1) Is there another implementation that runs faster than what I current have
and still thread-safe?
2) Maybe there is a way to duplicate a XmlDocument object and duplicating it
might be faster, if there is, I could just cache the 200 XmlDocument and
duplicate new one from there as requested.

Thanks for your comments and advice,
zeng


public static XmlDocument CreateXmlDoc( string xmlText )
{
XmlDocument xmlDoc = new XmlDocument();

System.IO.MemoryStream memStream = null;
XmlTextReader readerData = null;

try
{
System.Text.ASCIIEncoding e = new System.Text.ASCIIEncoding();

memStream = new MemoryStream( e.GetBytes( xmlText ) );
readerData = new XmlTextReader( memStream );
xmlDoc.Load( readerData );

}
finally
{
if( null != readerData )
readerData.Close();

if( null != memStream )
memStream.Close();
}
return xmlDoc;
}
 
C

Champika Nirosh

Hi Zeng,

In dot net you have two basic ways of manipulating a XML DOM, with
Xmldocument and SAX with XML text reader/writer etc..

So if teh requirement is to return a *XmlDocument* I think you may have less
option as far as teh performance increament is concern.. You may define your
XmlDocument object out side of ur method to slightly increase the
performance.. but ..

Depending on your requirement if you can process the data (if a sequencial
data reading) with a sax type reader that may indeed increase the
performance..

Regards,
Nirosh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top