Optimized heartbeat by calling Update() only on updated objects.

During the heartbeat loop, Update() is called on every SceneObjectGroup which in turn checks if any SceneObjectPart has changed. For large regions (> 100k prims) this work consumes 20-30% of a CPU even though there are only a few objects updating each frame.

There is only one other reason to check every object on every frame, and that is the case where a script has registered the object with an "at target" listener. We can easily track when an object is registered or unregistered with an AtTarget, so this is not a reason to check every object every heartbeat.

In the attached patch, I have added a dictionary to the scene which tracks the objects which have At Targets. Each heartbeat, the AtTarget() function will be called on every object registered with a listener for that event. Also, I added a dictionary to SceneGraph which stores references to objects which have been queued for updates during the heartbeat. At each heartbeat, Update() is called only on the objects which have generated updates during that beat.
This commit is contained in:
Dan Lake
2009-10-13 19:13:06 -07:00
committed by John Hurliman
parent e8c1e69a0d
commit 5976ac16b0
3 changed files with 52 additions and 73 deletions

View File

@@ -77,7 +77,7 @@ namespace OpenSim.Region.Framework.Scenes
protected RegionInfo m_regInfo;
protected Scene m_parentScene;
protected Dictionary<UUID, EntityBase> m_updateList = new Dictionary<UUID, EntityBase>();
protected Dictionary<UUID, SceneObjectGroup> m_updateList = new Dictionary<UUID, SceneObjectGroup>();
protected int m_numRootAgents = 0;
protected int m_numPrim = 0;
protected int m_numChildAgents = 0;
@@ -155,16 +155,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
protected internal void UpdateEntities()
{
List<EntityBase> updateEntities = GetEntities();
foreach (EntityBase entity in updateEntities)
{
entity.Update();
}
}
protected internal void UpdatePresences()
{
List<ScenePresence> updateScenePresences = GetScenePresences();
@@ -365,12 +355,12 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Add an entity to the list of prims to process on the next update
/// Add an object to the list of prims to process on the next update
/// </summary>
/// <param name="obj">
/// A <see cref="EntityBase"/>
/// A <see cref="SceneObjectGroup"/>
/// </param>
protected internal void AddToUpdateList(EntityBase obj)
protected internal void AddToUpdateList(SceneObjectGroup obj)
{
lock (m_updateList)
{
@@ -381,18 +371,18 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary>
/// Process all pending updates
/// </summary>
protected internal void ProcessUpdates()
protected internal void UpdateObjectGroups()
{
Dictionary<UUID, EntityBase> updates;
Dictionary<UUID, SceneObjectGroup> updates;
// Some updates add more updates to the updateList.
// Get the current list of updates and clear the list before iterating
lock (m_updateList)
{
updates = new Dictionary<UUID, EntityBase>(m_updateList);
updates = new Dictionary<UUID, SceneObjectGroup>(m_updateList);
m_updateList.Clear();
}
// Go through all timers
foreach (KeyValuePair<UUID, EntityBase> kvp in updates)
// Go through all updates
foreach (KeyValuePair<UUID, SceneObjectGroup> kvp in updates)
{
// Don't abort the whole update if one entity happens to give us an exception.
try