1

I am doing some experiments with IronPython 2.6.1 and the clr.CompileModules function to compile my large scripts into assemblies. Testing has shown good cold start performance performance improvements but in some cases importing the compiled module is actually slower than executing a large string that represents my code in some cases.

My question is, if i use something like

scope.Engine.Execute(string.Format("from {0} import {0}", theModule), scope);

or the ImportModule function, even though I get a new ScriptSCope back does the DLR cache the imports made in other ScriptScopes? So if module 1 and module 10 import the same type, I only take the performance hit once?

Is using clr.CompileModules preferable over scope.Compile()? My understanding is the on the fly compile is useful if I don’t want to manage extra assemblies and only want to pay the compile cost once.

1 Answer 1

1

The DLR doesn't cache the imports but IronPython does.

I think your understanding is correct - clr.CompileModules is usually good for a startup benefit. You can also combine it with ngen'ing the assemblies and you'll have even better startup perf. If you aren't doing that already then that's probably the reason you are seeing worse performance sometimes - we can avoid the JIT when compiling your code by interpreting it first, but if you compile we always need to JIT. Compiling + ngen is the best of both worlds other than needing to set all of that up.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've been running dotTrace over the application and the switch to compiled IronPython code definitely looks like the way forward for cold start performance. However I'm still seeing big time spent in ImportModule. I have one assembly with 29 modules included and I’m running "from foo import bar" inside the same scope then extracting the variable that is the class into C# for use. Will reducing the import dependencies these modules have decrease that import time is is that the import time of the module itself?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.