BendEg
BendEg

Reputation: 21128

No performance improvement when compiling code in IronPython

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

Upvotes: 1

Views: 189

Answers (1)

BendEg
BendEg

Reputation: 21128

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!

Upvotes: 1

Related Questions