1

I have the problem, that in some cases the Execute method for an ScriptSource takes a long time. This is problematic, because i use this method very often for the same ScriptSources. Now i tried to compile ScriptSource and save the result object. Then i use the Execute method on the compiled code, but this seems as slow as Execute on the ScriptSource directly.

I`ve made a simple example:

private static Dictionary<string, CompiledCode> compiledCode = new Dictionary<string, CompiledCode>();

// Method
public void LoadScript(string Name)
{
    if (compiledCode.ContainsKey(Name))
    {
        compiledCode[Name].Execute(scriptScope);
    }
    else
    {
        ScriptSource source = IronPythonScriptHost.Singleton.GetScriptSource(Name);
        CompiledCode code = source.Compile();
        compiledCode.Add(Name, code);
        code.Execute(scriptScope);     // Use an instanced ScriptScope                     
    }
}

Why is the compiled code not faster?

Or did i do somthing wrong in general?

Thank you

BendEg
  • 20,098
  • 17
  • 57
  • 131
  • I think, at most, it skips the parsing stage - which is quite fast (usually "unnoticeably so") already. The Python code is still Python executed by a Python runtime. – user2864740 Aug 04 '15 at 10:17
  • So my performance issue is not in the parsing then more in the executing process? But in my scripts i only have class definitions, not code that will be executed immediately... – BendEg Aug 04 '15 at 10:19

1 Answers1

1

I found the problem. In my case i am overwriting the Import method in IronPython and my own implementation is really slow, so the import part is my problem. I've now precompiled all modules and cache them, so accessing them in the import method is really fast. That's all, thank you!

BendEg
  • 20,098
  • 17
  • 57
  • 131