Use only one (static) (de-)serializer for (de-)serializing SOPs.

That improves performance drastically, at least for Mono, as the
(de-)serializers can then be optimized (and won't use reflection anymore).
On my system, before this change de-/serialization took ~9s/9s, whereas
after the change it takes ~.5/.2s.
0.6.2-post-fixes
Homer Horwitz 2009-01-02 17:22:24 +00:00
parent fbd664ca84
commit 09378da127
2 changed files with 27 additions and 6 deletions

View File

@ -401,9 +401,9 @@ namespace OpenSim.Region.Environment.Scenes
{
SetRootPart(part);
}
public SceneObjectGroup(string xmlData, bool isOriginalXmlFormat)
: this(UUID.Zero, xmlData, isOriginalXmlFormat)
: this(UUID.Zero, xmlData, isOriginalXmlFormat)
{
}
@ -423,7 +423,10 @@ namespace OpenSim.Region.Environment.Scenes
{
if (!isOriginalXmlFormat)
throw new Exception("This constructor must specify the xml is in OpenSim's original format");
m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
int time = System.Environment.TickCount;
// libomv.types changes UUID to Guid
xmlData = xmlData.Replace("<UUID>", "<Guid>");
xmlData = xmlData.Replace("</UUID>", "</Guid>");
@ -475,6 +478,7 @@ namespace OpenSim.Region.Environment.Scenes
reader.Close();
sr.Close();
m_log.DebugFormat("[SOG]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
/// <summary>
@ -487,6 +491,9 @@ namespace OpenSim.Region.Environment.Scenes
protected void SetFromXml(string xmlData)
{
m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
int time = System.Environment.TickCount;
// libomv.types changes UUID to Guid
xmlData = xmlData.Replace("<UUID>", "<Guid>");
xmlData = xmlData.Replace("</UUID>", "</Guid>");
@ -531,6 +538,8 @@ namespace OpenSim.Region.Environment.Scenes
reader.Close();
sr.Close();
m_log.DebugFormat("[SOG]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
protected virtual SceneObjectPart CreatePartFromXml(XmlTextReader reader)
@ -714,6 +723,9 @@ namespace OpenSim.Region.Environment.Scenes
public void ToXml(XmlTextWriter writer)
{
m_log.DebugFormat("[SOG]: Starting serialization of {0}", Name);
int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
m_rootPart.ToXml(writer);
@ -735,6 +747,9 @@ namespace OpenSim.Region.Environment.Scenes
writer.WriteEndElement();
writer.WriteEndElement();
m_log.DebugFormat("[SOG]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
public string ToXmlString2()
@ -752,6 +767,9 @@ namespace OpenSim.Region.Environment.Scenes
public void ToXml2(XmlTextWriter writer)
{
m_log.DebugFormat("[SOG]: Starting serialization of SOG {0} to XML2", Name);
int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
m_rootPart.ToXml(writer);
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
@ -769,6 +787,7 @@ namespace OpenSim.Region.Environment.Scenes
writer.WriteEndElement();
writer.WriteEndElement();
m_log.DebugFormat("[SOG]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
}
/// <summary>

View File

@ -96,7 +96,11 @@ namespace OpenSim.Region.Environment.Scenes
public class SceneObjectPart : IScriptHost, ISerializable
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// use only one serializer to give the runtime a chance to optimize it (it won't do that if you
// use a new instance every time)
private static XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
#region Fields
[XmlIgnore]
@ -1619,7 +1623,6 @@ if (m_shape != null) {
/// <returns></returns>
public static SceneObjectPart FromXml(UUID fromUserInventoryItemId, XmlReader xmlReader)
{
XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
SceneObjectPart part = (SceneObjectPart)serializer.Deserialize(xmlReader);
part.m_fromUserInventoryItemID = fromUserInventoryItemId;
@ -3186,7 +3189,6 @@ if (m_shape != null) {
/// <param name="xmlWriter"></param>
public void ToXml(XmlWriter xmlWriter)
{
XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
serializer.Serialize(xmlWriter, this);
}