From 83bfd29af889631ed2f22e774d50d80aa1ceb198 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sun, 25 May 2008 19:26:21 +0000 Subject: [PATCH] Thank you very much, Xantor for a patch that: Copying, reseting, dragging scripts cause unnecessary recompilation, slowing down the simulator and filling up the ScriptEngines directory with compiled .dll and misc. files. This patch keeps track of compiled assets since the last simulator restarts, and only recompiles new assets. (editing a script generates a new asset, so no problems there). --- .../Common/ScriptEngineBase/ScriptManager.cs | 4 +++ .../DotNetEngine/ScriptManager.cs | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs index c84975ad1a..366aaf1498 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs @@ -81,12 +81,16 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase Unload = 2 } + // Xantor 20080525: Keep a list of compiled scripts this session for reuse + public Dictionary scriptList = new Dictionary(); + // Object> // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! public Dictionary> Scripts = new Dictionary>(); + public Scene World { get { return m_scriptEngine.World; } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 55289d9162..a328a58738 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -26,6 +26,8 @@ */ using System; +using System.Reflection; +using log4net; using libsecondlife; using OpenSim.Framework; using OpenSim.Region.Environment.Scenes; @@ -43,6 +45,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } private Compiler.LSL.Compiler LSLCompiler; + private static readonly ILog m_log + = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public override void Initialize() { @@ -70,10 +75,31 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine SceneObjectPart m_host = World.GetSceneObjectPart(localID); + // Xantor 20080525: I need assetID here to see if we already compiled this one previously + LLUUID assetID = LLUUID.Zero; + TaskInventoryItem taskInventoryItem = new TaskInventoryItem(); + if(m_host.TaskInventory.TryGetValue(itemID,out taskInventoryItem)) + assetID = taskInventoryItem.AssetID; + + try { - // Compile (We assume LSL) - CompiledScriptFile = LSLCompiler.PerformScriptCompile(Script); + // Xantor 20080525 see if we already compiled this script this session, stop incessant recompiling on + // scriptreset, spawning of objects with embedded scripts etc. + + if (scriptList.TryGetValue(assetID, out CompiledScriptFile)) + { + m_log.InfoFormat("[SCRIPT]: Found existing compile of assetID {0}: {1}", assetID, CompiledScriptFile); + } + else + { + // Compile (We assume LSL) + CompiledScriptFile = LSLCompiler.PerformScriptCompile(Script); + + // Xantor 20080525 Save compiled scriptfile for later use + m_log.InfoFormat("[SCRIPT]: Compiled assetID {0}: {1}", assetID, CompiledScriptFile); + scriptList.Add(assetID, CompiledScriptFile); + } //#if DEBUG //long before;