Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XmlSerializer slow to construct
Message
De
29/04/2011 09:08:11
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
XmlSerializer slow to construct
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Divers
Thread ID:
01508806
Message ID:
01508806
Vues:
101
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform