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