On code section that rezzes single objects and attachments, reduce CPU use by reading asset XML a single time with a stream reader rather than multiple times.
Reading large XML documents (e.g. complex attachments) is CPU expensive - this must be done as few times as possible (preferably just once). Reading these documents into XmlDocument is also more resource intensive than using XmlTextReader, as per Microsoft's own publication "Improve .NET Application Performance and Scalability" Optimization of other cases will follow if this change is successful.bullet-2.82
parent
b1ff78f4d8
commit
f132f642b2
|
@ -829,7 +829,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
|
|||
byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0);
|
||||
Vector3 pos;
|
||||
|
||||
bool single = m_Scene.GetObjectsToRez(rezAsset.Data, attachment, out objlist, out veclist, out bbox, out offsetHeight);
|
||||
bool single
|
||||
= m_Scene.GetObjectsToRez(
|
||||
rezAsset.Data, attachment, out objlist, out veclist, out bbox, out offsetHeight);
|
||||
|
||||
if (single)
|
||||
{
|
||||
|
|
|
@ -111,6 +111,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests
|
|||
InventoryFolderBase objsFolder
|
||||
= InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, m_userId, "Objects")[0];
|
||||
item1.Folder = objsFolder.ID;
|
||||
item1.Flags |= (uint)InventoryItemFlags.ObjectHasMultipleItems;
|
||||
m_scene.AddInventoryItem(item1);
|
||||
|
||||
SceneObjectGroup so
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
|||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Timers;
|
||||
using System.Xml;
|
||||
using OpenMetaverse;
|
||||
|
@ -2192,34 +2193,45 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
/// Returns one object if the asset is a regular object, and multiple objects for a coalesced object.
|
||||
/// </remarks>
|
||||
/// <param name="assetData">Asset data</param>
|
||||
/// <param name="attachment">Whether the item is an attachment</param>
|
||||
/// <param name="isAttachment">True if the object is an attachment.</param>
|
||||
/// <param name="objlist">The objects included in the asset</param>
|
||||
/// <param name="veclist">Relative positions of the objects</param>
|
||||
/// <param name="bbox">Bounding box of all the objects</param>
|
||||
/// <param name="offsetHeight">Offset in the Z axis from the centre of the bounding box
|
||||
/// to the centre of the root prim (relevant only when returning a single object)</param>
|
||||
/// <returns>true = returning a single object; false = multiple objects</returns>
|
||||
public bool GetObjectsToRez(byte[] assetData, bool attachment, out List<SceneObjectGroup> objlist, out List<Vector3> veclist,
|
||||
/// <returns>
|
||||
/// true if returning a single object or deserialization fails, false if returning the coalesced
|
||||
/// list of objects
|
||||
/// </returns>
|
||||
public bool GetObjectsToRez(
|
||||
byte[] assetData, bool isAttachment, out List<SceneObjectGroup> objlist, out List<Vector3> veclist,
|
||||
out Vector3 bbox, out float offsetHeight)
|
||||
{
|
||||
objlist = new List<SceneObjectGroup>();
|
||||
veclist = new List<Vector3>();
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
string xmlData = Utils.BytesToString(assetData);
|
||||
doc.LoadXml(xmlData);
|
||||
XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
|
||||
|
||||
if (e == null || attachment) // Single
|
||||
try
|
||||
{
|
||||
SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
|
||||
using (XmlTextReader reader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
|
||||
{
|
||||
reader.Read();
|
||||
bool isSingleObject = reader.Name != "CoalescedObject";
|
||||
|
||||
if (isSingleObject || isAttachment)
|
||||
{
|
||||
SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(reader);
|
||||
objlist.Add(g);
|
||||
veclist.Add(new Vector3(0, 0, 0));
|
||||
veclist.Add(Vector3.Zero);
|
||||
bbox = g.GetAxisAlignedBoundingBox(out offsetHeight);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xmlData);
|
||||
XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
|
||||
XmlElement coll = (XmlElement)e;
|
||||
float bx = Convert.ToSingle(coll.GetAttribute("x"));
|
||||
float by = Convert.ToSingle(coll.GetAttribute("y"));
|
||||
|
@ -2243,10 +2255,23 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
float z = Convert.ToSingle(rawZ);
|
||||
veclist.Add(new Vector3(x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error(
|
||||
"[AGENT INVENTORY]: Deserialization of xml failed when looking for CoalescedObject tag. Exception ",
|
||||
e);
|
||||
|
||||
bbox = Vector3.Zero;
|
||||
offsetHeight = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event Handler Rez an object into a scene
|
||||
|
|
|
@ -902,6 +902,34 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
}
|
||||
}
|
||||
|
||||
public void LoadScriptState(XmlTextReader reader)
|
||||
{
|
||||
// m_log.DebugFormat("[SCENE OBJECT GROUP]: Looking for script state for {0} in {1}", Name);
|
||||
|
||||
while (reader.ReadToFollowing("SavedScriptState"))
|
||||
{
|
||||
// m_log.DebugFormat("[SCENE OBJECT GROUP]: Loading script state for {0}", Name);
|
||||
|
||||
if (m_savedScriptState == null)
|
||||
m_savedScriptState = new Dictionary<UUID, string>();
|
||||
|
||||
string uuid = reader.GetAttribute("UUID");
|
||||
|
||||
if (uuid != null)
|
||||
{
|
||||
// m_log.DebugFormat("[SCENE OBJECT GROUP]: Found state for item ID {0} in object {1}", uuid, Name);
|
||||
|
||||
UUID itemid = new UUID(uuid);
|
||||
if (itemid != UUID.Zero)
|
||||
m_savedScriptState[itemid] = reader.ReadInnerXml();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("[SCENE OBJECT GROUP]: SavedScriptState element had no UUID in object {0}", Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hooks this object up to the backup event so that it is persisted to the database when the update thread executes.
|
||||
/// </summary>
|
||||
|
|
|
@ -58,58 +58,59 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
|
|||
/// <param name="xmlData"></param>
|
||||
/// <returns>The scene object deserialized. Null on failure.</returns>
|
||||
public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
|
||||
{
|
||||
using (XmlTextReader reader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
|
||||
return FromOriginalXmlFormat(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize a scene object from the original xml format
|
||||
/// </summary>
|
||||
/// <param name="xmlData"></param>
|
||||
/// <returns>The scene object deserialized. Null on failure.</returns>
|
||||
public static SceneObjectGroup FromOriginalXmlFormat(XmlTextReader reader)
|
||||
{
|
||||
//m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
|
||||
//int time = System.Environment.TickCount;
|
||||
|
||||
SceneObjectGroup sceneObject = null;
|
||||
|
||||
try
|
||||
{
|
||||
StringReader sr;
|
||||
XmlTextReader reader;
|
||||
XmlNodeList parts;
|
||||
XmlDocument doc;
|
||||
int linkNum;
|
||||
|
||||
doc = new XmlDocument();
|
||||
doc.LoadXml(xmlData);
|
||||
parts = doc.GetElementsByTagName("RootPart");
|
||||
reader.ReadToFollowing("RootPart");
|
||||
reader.ReadToFollowing("SceneObjectPart");
|
||||
sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
|
||||
reader.ReadToFollowing("OtherParts");
|
||||
|
||||
if (parts.Count == 0)
|
||||
throw new Exception("Invalid Xml format - no root part");
|
||||
|
||||
sr = new StringReader(parts[0].InnerXml);
|
||||
reader = new XmlTextReader(sr);
|
||||
SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
|
||||
reader.Close();
|
||||
sr.Close();
|
||||
|
||||
parts = doc.GetElementsByTagName("Part");
|
||||
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
if (reader.ReadToDescendant("Part"))
|
||||
{
|
||||
do
|
||||
{
|
||||
if (reader.ReadToDescendant("SceneObjectPart"))
|
||||
{
|
||||
sr = new StringReader(parts[i].InnerXml);
|
||||
reader = new XmlTextReader(sr);
|
||||
SceneObjectPart part = SceneObjectPart.FromXml(reader);
|
||||
linkNum = part.LinkNum;
|
||||
sceneObject.AddPart(part);
|
||||
part.LinkNum = linkNum;
|
||||
part.TrimPermissions();
|
||||
reader.Close();
|
||||
sr.Close();
|
||||
}
|
||||
}
|
||||
while (reader.ReadToNextSibling("Part"));
|
||||
}
|
||||
|
||||
// Script state may, or may not, exist. Not having any, is NOT
|
||||
// ever a problem.
|
||||
sceneObject.LoadScriptState(doc);
|
||||
|
||||
return sceneObject;
|
||||
sceneObject.LoadScriptState(reader);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
|
||||
m_log.ErrorFormat("[SERIALIZER]: Deserialization of xml failed. Exception {0}", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return sceneObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue