IronPython 编译代码的导入性能
我正在使用 IronPython 2.6.1 和 clr.CompileModules 函数进行一些实验,以将大型脚本编译成程序集。测试显示冷启动性能得到了良好的改进,但在某些情况下,导入已编译的模块实际上比执行代表我的代码的大字符串要慢。
我的问题是,如果我使用类似
scope.Engine.Execute(string.Format("from {0} import {0}", theModule), scope);
ImportModule
函数,即使我得到一个新的 ScriptSCope,DLR 是否会缓存在其他 ScriptScope 中进行的导入?那么如果模块 1 和模块 10 导入相同的类型,我只会受到一次性能影响?
使用 clr.CompileModules 比使用scope.Compile() 更好吗?我的理解是,如果我不想管理额外的程序集并且只想支付一次编译成本,则动态编译很有用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DLR 不会缓存导入,但 IronPython 会缓存。
我认为您的理解是正确的 - clr.CompileModules 通常有利于启动。您还可以将其与 ngen'ing 程序集结合起来,您将获得更好的启动性能。如果您还没有这样做,那么这可能就是您有时看到性能较差的原因 - 我们可以在编译代码时通过首先解释它来避免 JIT,但如果您编译,我们总是需要 JIT。除了需要设置所有这些之外,编译 + ngen 是两全其美的。
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.