有关可能的Java(或其他内存管理语言)优化的问题 [英] Questions about possible java(or other memory managed language) optimizations

查看:108
本文介绍了有关可能的Java(或其他内存管理语言)优化的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我所读的Java(通常)来看,似乎可以将Java编译为不是很优化(完全是?)的Java字节码,因此只能通过jit进行优化。这是真的?并且是否进行了任何探索(可能是在其他实现方式中)让编译器优化代码,从而使jit要做的工作更少(有可能)吗?

From what I have read java (usually) seems to compile java to not very (is at all?) optimised java bytecode, leaving it to the jit to optimise. Is this true? And if it is has there been any exploration (possibly in alternative implementations) of getting the compiler to optimise the code so the jit has less work to do (is this possible)?

还有很多人似乎不喜欢Java(以及许多其他高级内存管理语言)的本机代码生成(有时称为提前编译),原因很多,例如可移植性下降(等等)。 ,但部分原因是因为(至少对于那些具有即时编译器的语言而言)人们认为,提前编译为机器代码将错过jit编译器可能进行的优化,因此在编译过程中可能较慢长跑。

Also many people seem to have a dislike for native code generation (sometimes referred to as ahead of time compilation) for Java (and many other high level memory managed languages) , for many reasons such as loss of portability (and ect.) , but also partially because (at least for those languages that have a just in time compiler) the thinking goes that ahead of time compilation to machine code will miss the possible optimisations that can be done by a jit compiler and therefore may be slower in the long run.

这使我想知道是否有人尝试实现 http://zh.wikipedia.org/wiki/Profile-guided_optimization (编译为二进制+一些其他代码,然后运行程序并分析测试运行时的运行时信息,以期产生更多希望针对Java /(其他内存管理语言)的用于现实世界的优化二进制代码,这与jit代码相比如何?有人知道吗?

This leads me to wonder whether anyone has ever tried to implement http://en.wikipedia.org/wiki/Profile-guided_optimization (compiling to a binary + some extras then running the program and analysing the runtime information of the test run to generate a hopefully more optimised binary for real world usage) for java/(other memory managed languages) and how this would compare to jit code? Anyone have a clue?

推荐答案

配置文件引导的优化有一些警告,甚至在您链接的Wiki文章中也提到了其中一些警告。对于给定的示例,结果是有效的

Profile-guided optimization has some caveats, one of them mentioned even in the Wiki article you linked. It's results are valid


  • ,表示用户或其他代码实际使用您的代码的方式。

  • 对于给定的平台(CPU,内存和其他硬件,OS,等等)。

    从性能的角度来看,即使通常考虑的平台之间也存在很大差异(更多)或更少)(例如,将单核,具有512M的旧Athlon与具有8G的6核Intel,运行在Linux上,但内核版本非常不同)。

  • JVM及其配置。

如果这些更改有任何变化,则分析结果(以及基于它们的优化)将不再有效。最有可能的一些优化仍然会产生有益的效果,但是其中一些优化可能会导致效果不佳(甚至会降低性能)。

If any of these change then your profiling results (and the optimizations based on them) are not necessary valid any more. Most likely some of the optimizations will still have a beneficial effect, but some of them may turn out suboptimal (or even degrading performance).

如前所述,JIT JVM进行与剖析非常相似的操作,但是它们是即时进行的。它也称为热点,因为它会不断监视执行的代码,查找经常执行的热点,并会尝试仅优化那些部分。在这一点上,它将能够利用有关代码的更多知识(了解代码的上下文,其他类如何使用它,等等),因此-正如您和其他答案所提到的-作为更好的优化,它可以静态的。它会继续监视,如果需要,它将在以后进行另一轮优化,这一次将更加努力(寻找更多,更昂贵的优化)。

处理现实数据(使用统计+平台) +配置)可以避免前面提到的警告。

As it was mentioned the JIT JVMs do something very similar to profiling, but they do it on the fly. It's also called 'hotspot', because it constantly monitors the executed code, looks for hot spots that are executed frequently and will try to optimize only those parts. At this point it will be able to exploit more knowledge about the code (knowing the context of it, how it is used by other classes, etc.) so - as mentioned by you and the other answers - it can do better optimizations as a static one. It will continue monitoring and if its needed it will do another turn of optimization later, this time trying even harder (looking for more, more expensive optimizations).
Working on the real life data (usage statistics + platform + config) it can avoid the caveats mentioned before.

它的价格是需要花更多时间在性能分析和JIT-ing上。

The price of it is some additional time it needs to spend on "profiling" + JIT-ing. Most of the time its spent quite well.

我认为配置文件引导的优化器仍然可以与它竞争(甚至胜过它),但只有在某些特殊情况下,如果您可以避免以下警告:

I guess a profile-guided optimizer could still compete with it (or even beat it), but only in some special cases, if you can avoid the caveats:


  • 您非常确定您的样本很好地代表了现实生活中的场景,并且它们的变化不会太大在执行过程中。

  • 您非常准确地了解目标平台,并且可以在其上进行性能分析。

  • 当然,您知道/控制JVM和它的配置。

这种情况很少发生,我想一般而言,JIT会为您带来更好的结果,但是我没有证据。

It will happen rarely and I guess in general JIT will give you better results, but I have no evidence for it.

如果您针对无法进行JIT优化的JVM(我认为大多数小型设备都具有这样的JVM),则可以从配置文件引导的优化中获取价值。

Another possibility for getting value from the profile-guided optimization if you target a JVM that can't do JIT optimization (I think most small devices have such a JVM).

BTW其他答案中提到的一个缺点很容易避免:如果静态/配置文件引导的优化缓慢( b)
我认为更大的问题将是拥有良好的样本,这可能仅适用于发行版(或去测试人员的RC)或夜间构建(时间无关紧要)。测试用例。创建和维护它们通常并不容易,并且需要大量时间。尤其是如果您希望能够自动执行它们,在这种情况下这将非常重要。

BTW one disadvantage mentioned in other answers would be quite easy to avoid: if static/profile guided optimization is slow (which is probably the case) then do it only for releases (or RCs going to testers) or during nightly builds (where time does not matter so much).
I think the much bigger problem would be to have good sample test cases. Creating and maintaining them is usually not easy and takes a lot of time. Especially if you want to be able to execute them automatically, which would be quite essential in this case.

这篇关于有关可能的Java(或其他内存管理语言)优化的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆