From 5976ac16b0eedaeca2360010a3d6f7be4213700a Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Tue, 13 Oct 2009 19:13:06 -0700 Subject: 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. --- OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 6a10618..d4cef7d 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1234,6 +1234,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_targets) m_targets.Clear(); + m_scene.RemoveGroupTarget(this); } ScheduleGroupForFullUpdate(); @@ -1864,12 +1865,6 @@ namespace OpenSim.Region.Framework.Scenes m_rootPart.UpdateFlag = 1; lastPhysGroupPos = AbsolutePosition; } - //foreach (SceneObjectPart part in m_parts.Values) - //{ - //if (part.UpdateFlag == 0) part.UpdateFlag = 1; - //} - - checkAtTargets(); if (UsePhysics && ((Math.Abs(lastPhysGroupRot.W - GroupRotation.W) > 0.1) || (Math.Abs(lastPhysGroupRot.X - GroupRotation.X) > 0.1) @@ -3114,6 +3109,7 @@ namespace OpenSim.Region.Framework.Scenes { m_targets.Add(handle, waypoint); } + m_scene.AddGroupTarget(this); return (int)handle; } @@ -3121,12 +3117,13 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_targets) { - if (m_targets.ContainsKey((uint)handle)) - m_targets.Remove((uint)handle); + m_targets.Remove((uint)handle); + if (m_targets.Count == 0) + m_scene.RemoveGroupTarget(this); } } - private void checkAtTargets() + public void checkAtTargets() { if (m_scriptListens_atTarget || m_scriptListens_notAtTarget) { -- cgit v1.1