Performance benefits of recompiling old java project with the latest java version

Viewed 439

Does it make sense to recompile a project with a new (java 11) target version from a performance perspective if it will be run on a java 11 while source code will remain the same (java 8)?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
      <source>11</source>
      <target>11</target>
    </configuration>
  </plugin>

What are pitfalls to run java 8 bytecode on a newer JVM?

Update:

Code optimizer is one of the phases of compilation phase, where:

  • It helps you to establish a trade-off between execution and compilation speed
  • Improves the running time of the target program
  • Generates streamlined code still in intermediate representation
  • Removing unreachable code and getting rid of unused variables
  • Removing statements which are not altered from the loop
  • etc

read more: https://www.guru99.com/compiler-design-phases-of-compiler.html

So, I wonder if it's a big difference between different compilers (benchmarks), would be nice to have a full list of all optimization happens on a compilation phase

1 Answers

No, the javac compiler doesn't do much optimization as JIT is responsible for most optimizations during runtime, so you'd be getting pretty identical bytecode. Except the class file would be marked as Java 11, so you wouldn't be able to run it on a lower version.

Java is backwards compatible, so running Java 8 bytecode on newer versions is nothing special.

Of course running Java 8 bytecode on a newer JVM allows (possible) improved dynamic optimizations in the JIT to be used, so you're more likely to get improved performance just using a later JVM without any additional compilation.

As Johannes' video shows there's always interest to optimize Strings for memory and speed, since they're the most commonly used objects in Java projects. However it's still a microbenchmark, and most of the differences come from code compiled and run with Java 11 vs. code compiled and run with Java 8.

I tried to find sources that would address the recompilation, but couldn't find anything with a quick peek. So until there's evidence that non-microbenchmarks would benefit (realistic, not theoretical) from recompilation to Java 11 bytecode, I'll classify it under "Performance Voodoo".

Related