我如何制作 Pydev + jython 在运行脚本时启动速度更快?

发布于 2024-08-05 19:49:56 字数 118 浏览 2 评论 0原文

我正在使用 pydev + jython.great ide ,但是当我尝试运行 jython 程序时速度相当慢。 这可能是由于库加载时间造成的。

我可以做什么来加快速度?

谢谢 , 亚尼夫

i'm working with pydev + jython.great ide , but quite slow when i try to run a jython program.
this is probably something due to libraries load time.

What can i do to speed it up ?

Thanks ,
yaniv

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

血之狂魔 2024-08-12 19:49:56

Jython 启动时间很慢...有很多东西需要启动!

每次从头开始运行 Jython 脚本时,都会产生相同的 Jython 启动时间成本。

因此,Jython、Java 和 Python 不太适合 CGI 调用。这就是 Apache 中 mod_python 的原因。

关键是启动 Jython 一次并重复使用它。但这并不总是可能的,尤其是在开发期间,因为您的模块总是在变化,而 Jython 不会自动识别这些变化。

Jython 需要一种方法来了解哪些模块已更改以进行自动重新加载。这没有内置到 Jython 中,您必须依赖其他一些第三方库来帮助完成此操作。这个概念是从“sys.modules”中删除已更改的模块。一个简单的解决方案是从 sys.modules 中清除所有模块 - 这将导致所有模块重新加载。显然,这不是最有效的解决方案。

另一个技巧是仅在模块“真正”需要时导入模块所需的模块。如果您在模块顶部导入每个模块,则会增加模块导入成本。因此,将导入重构到需要它们并且“有意义”的方法/函数内。当然,如果您的方法/函数计算量很大并且经常使用,则在该方法/函数中导入模块是没有意义的。

希望这对您有所帮助!

Jython startup time is slow ... there's a lot to bootup!

Everytime you run a Jython script from scratch, it will incur the same Jython startup time cost.

Hence, the reason Jython, Java, and Python are not great for CGI invocations. Hence, the reason for mod_python in Apache.

The key is to start-up Jython once and reuse it. But this is not always possible especially during development because your modules are always changing and Jython does not recognize these changes automatically.

Jython needs a way to know which modules have changed for automatic reloads. This is not built into Jython and you'll have to rely on some other third party library to help with this. The concept is to remove from 'sys.modules' the modules which have changed. A simple solution is to just clear all the modules from sys.modules - which will cause all modules to be reloaded. This is obviously, not the most efficient solution.

Another tip is to only import modules that your module needs at the time that it 'really' needs them. If you import every module at the top of your modules, that will increase your module import cost. So, refactor imports to within methods/functions where they are needed and where it 'makes sense'. Of course, if your method/function is computation heavy and is used frequently, it does not make sence to import modules within that method/function.

Hopefully, that helps you out!

ぃ双果 2024-08-12 19:49:56

如果您的机器具有多个处理器,您可以尝试使用选项 -vmargs -XX:+UseParallelGC 启动 eclipse/pydev 您还可以尝试不同的 JVM,看看它们中的任何一个是否能提供更好的性能。

If you have a machine with more than one processor you could try starting eclipse/pydev with the options -vmargs -XX:+UseParallelGC You could also try different JVMs to see if any of them give better performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文