热点JIT优化和“反优化”:如何强制FASTEST?

发布于 2024-10-31 13:34:40 字数 385 浏览 1 评论 0原文

我有一个正在尝试优化的大型应用程序。 为此,我通过在循环中运行数百万次来对其小元素进行分析/基准测试,并检查它们的处理时间。

显然 Hotspot 的 JIT 正在发挥作用,我实际上可以看到这种情况何时发生。 我喜欢它,我可以清楚地看到“热身”期过后事情进展得更快。

然而,在达到最快的执行速度并保持一段时间后,我可以看到速度随后降低到不太令人印象深刻的速度,并且保持在那里。

循环中执行的内容实际上并没有太大变化,所以我很难理解为什么转义分析会强制代码“去优化”。

基本上,我感觉 JIT 获得了最佳性能,然后满足于较慢的速度,认为这“足够了”。

有什么方法可以告诉他“这还不够,我真的希望代码运行得尽可能快!”。 我知道它可以,因为它已经做到了。我怎样才能强迫它这样做呢?

I have a BIG application that I'm trying to optimize.
to do so, I'm profiling / benchmarking small elements of it by running them millions of times in a loop, and checking their processing time.

obviously Hotspot's JIT is kicking in, and I can actually see when that happens.
I like it, I can clearly see things going much faster after the "warm up" period.

however, after reaching the fastest execution speed and keeping it for some time, I can see that the speed is then reduced to a less impressive one, and it stays there.

what's executed in the loop does not actually change much, so I can hardly see why escape analysis would force a "de-optimization" of code.

basically I get the feeling the JIT is getting the best performance, then settles for something slower, thinking that it's "enough".

is there any way to tell him "it's not enough, I really want that code to run as fast as possible !".
I know it can as it already did. Just how can I force it to do so ?

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

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

发布评论

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

评论(2

回忆追雨的时光 2024-11-07 13:34:40

不可能用“产品”(读取正常发布的)构建来跟踪,我会将代码放入您的套件中并查看发生了什么,热点将始终尝试获得最佳的优化。

如果您的代码在 jit 中强制进行去优化,那么速度只会变慢,在分析器中您应该能够将其视为大量分配、大量异常等情况。

Its impossible to trace with a "product" (read normal released) build, I would put the code through yourkit and see what's happening, hotspot will try to get the best possible optimisation at all times.

It will only go slower if you have code that forces de-optimisation in the jit, in the profiler you should be able to see this as things like large numbers of allocations, huge number of exceptions.

夜未央樱花落 2024-11-07 13:34:40

您应该使用 VisualVM 来查找内存泄漏和 CPU 使用问题,它是 JDK 附带的。它非常适合分析,并且有很多插件。您还可以在应用程序运行时自动从 Eclipse 启动 VisualVM。 Netbeans 可能也有类似的东西。如果您使用采样而不是分析,它也不会对性能产生太大影响。

我过去更喜欢 JRockIt Mission Control,而不是这个(使用 JRockIt VM),但现在这个已经可以了。

VisualVM

You should use VisualVM to find memory leaks and CPU usage problems, which comes with the JDK. It's pretty good for profiling, and has many plugins. You can also start VisualVM from Eclipse automatically when an application runs. Netbeans probably has something similar. It also doesn't impact performance much, providing that you use sampling rather than profiling.

I used to prefer JRockIt Mission Control over this (with JRockIt VM), but this does the job these days.

VisualVM

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