简体   繁体   English

在现代项目中使用具有较旧语言级别的JAR会对性能产生什么影响?

[英]What are the performance implications of using a JAR with an older language level in a modern project?`

I work in a corporate environment with several widely-used, infrequently-updated Java libraries in its repositories. 我在一个企业环境中工作,在其存储库中有几个广泛使用的,不经常更新的Java库。 Some of the libraries quite old, and were compiled using language levels as far back as JDK 1.5 (Java 5). 一些库很老,并且使用语言级别编译,早在JDK 1.5(Java 5)。

Nearly all of our actively developed Java projects are using Java 8 or newer, but they are dependent on one or more of the JDK 1.5-level JARs. 几乎所有积极开发的Java项目都使用Java 8或更新版本,但它们依赖于一个或多个JDK 1.5级JAR。

Are there performance penalties for using JARs with very old bytecode versions? 使用具有非常旧的字节码版本的JAR会有性能损失吗? Can the modern JIT update old, inefficient bytecode on the fly? 现代JIT可以动态更新旧的,低效的字节码吗?

Remember: Write Once , Run Everywhere! 记住: 写一次 ,到处跑! In your case, the slogan really fits. 在你的情况下,口号真的适合。

Generally, there's no reason to touch old Java code if it's doing its job. 通常,如果它正在执行其工作,则没有理由触及旧的Java代码。

The bytecode hasn't changed much over the years, the bytecode instructions understood by a Java8 JRE are 99% the same that were present already in Java2 - there were very few additions, so from that point of view there's no need to update the old bytecode. 多年来字节码没有太大变化,Java8 JRE理解的字节码指令与Java2中已经存在的99%相同 - 只有很少的添加,所以从这个角度来看,没有必要更新旧的字节码。 It will run even faster under Java8 than under Java5, as both the JRE with its HotSpot engine and the class library have improved a lot. 它在Java8下比在Java5下运行得更快,因为带有HotSpot引擎的JRE和类库都有了很大的改进。

The changes in the class file format are more about metadata, and the class-file version number also makes sure that you don't run a Java8 program under a Java6 JRE where half of the Java classes and methods are missing. 类文件格式的更改更多地是关于元数据,类文件版本号还确保您不在Java6 JRE下运行Java8程序,其中缺少一半的Java类和方法。

What changed a lot, is the Java class library and the source language. 更改的是Java类库和源语言。 And as an old library couldn't know about the changes to come later, it might turn out to be less efficient than a newly-written version using all the features from later Java releases. 而且由于旧的库无法知道稍后会发生的变化,因此使用后来Java版本中的所有功能的新编写版本可能效率低下。 But my guess is that the performance gained by a redesign of the old libraries isn't worth the effort. 但我的猜测是,重新设计旧库所获得的性能并不值得。

And finally the general advice on performance questions: 最后是关于性能问题的一般建议:

  • If it ain't broken, don't fix it (= don't optimize before you know that you have a performance problem). 如果没有损坏,请不要修复它(=在您知道性能问题之前不要进行优化)。

  • Before optimizing, use a profiler to find out where your bottlenecks are. 在优化之前,使用分析器找出瓶颈所在。 Believe me, the bottleneck is hardly ever where you expect it. 相信我,瓶颈几乎没有你想象的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM