Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XmlSerializer slow to construct
Message
From
29/04/2011 09:08:11
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
XmlSerializer slow to construct
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01508806
Message ID:
01508806
Views:
99
Hi all,

I am tracing some code that is performing slowly and found this method to be very slow in performance compared to the rest of the code in the cycle. It appears from the trace that constructing an XmlSerializer is not very quick amongst other issues Microsoft has noted with Memory (see link below).

I am wondering about other alternatives or obvious choices you might see that could be done to speed this up. I am looking into if it is possible to keep the XmlSerializer around instead of constructing it several times but not sure if that will be a reasonable choice yet.

I also attached a screen shot of the dot trace showing the performance metrics to this code.
Thanks

Microsoft Link
http://support.microsoft.com/kb/886385
public XmlSerializer GetXmlSerializer(Type type)
{
	XmlSerializer serializer;
	lock (SerializerCache)
	{
		if (SerializerCache.ContainsKey(type))
		{
			serializer = SerializerCache[type];
		}
		else
		{
			// Next line of code is VERY slow comparitavily and it isn't the ToArray() call.
			serializer = new XmlSerializer(type, SerializationTypesList.ToArray());
			serializer.UnknownNode += this.XmlSerializer_UnknownNode;
			serializer.UnreferencedObject += this.XMLSerializer_UnreferencedObject;
			serializer.UnknownElement += this.XMLSerializer_UnknownElement;
			serializer.UnknownAttribute += this.XMLSerializer_UnknownAttribute;
			SerializerCache.Add(type, serializer);
		}
	}
	return serializer;
}
Timothy Bryan
Next
Reply
Map
View

Click here to load this message in the networking platform