Goodbye, Java 8! Java 17 turned out to be the fastest JDK in history

Java 17 has been officially released, and the new version provides many new features and functional enhancements. However, for most projects, it is often necessary to change the code to take advantage of these new changes, except for performance-developers only need to upgrade the JDK version to get performance improvements for free.

Planning the scheduling engine OptaPlanner project leader compared the performance benchmarks of JDK 17, JDK 16 and JDK 11 to see if the performance improvement of Java 17 is worth upgrading.

# Test environment and process

1. Hardware

A stable machine, without any other processes required for calculations running.

Configure Intel® Xeon® Silver 4116 @ 2.1 GHz (12 cores total / 24 threads), 128 GiB RAM, RHEL 8 x86_64

2. JDKs (for compiling and running)

JDK 11

openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

JDK 16

openjdk 16.0.2 2021-07-20
OpenJDK Runtime Environment (build 16.0.2+7-67)
OpenJDK 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)

JDK 17 (download date is 2021-09-06)

openjdk 17 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)

3. JVM options

Enable -Xmx3840M and specify the garbage collector explicitly:

  • -XX:+UseG1GC for G1GC, low-latency garbage collector (the default item for the three JDK versions)
  • -XX:+UseParallelGC for ParallelGC, high throughput garbage collector

4.Main class, from the optaplanner-examples module in OptaPlanner 8.10.0.Final

  • Each run uses OptaPlanner to solve 11 planning problems, such as employee scheduling, school timetables, and cloud optimization. Each planning question runs for 5 minutes. Logging is set to INFO. The benchmark test started with a 30-second JVM warm-up.
  • Solving the planning problem does not involve IO (except for the few milliseconds that load the input during startup). A single CPU is fully saturated. It will continue to create many short-lived objects, and then GC will collect them.
  • Benchmarks measure the number of scores calculated per second, with higher scores representing better performance. Calculating the score for the proposed planning solution is not easy: it involves many calculations, including checking for conflicts between each entity and each other entity.

5. Number of runs

Each JDK and each garbage collector combination runs 3 times in sequence. The result below is the average of these 3 runs.

# Test Results

Java 11 (LTS) and Java 16 versus Java 17 (LTS)

Java 16 versus Java 17

G1GC versus ParallelGC on Java 17

G1GC versus ParallelGC on Java 17

# SummarizeBased on OptaPlanner use cases, these benchmarks show that

  • For G1GC (default), Java 17 is 8.66% faster than Java 11 and 2.41% faster than Java 16
  • For ParallelGC, Java 17 is 6.54% faster than Java 11 and 0.37% faster than Java 16
  • Parallel GC is 16.39% faster than G1 GC

In short, the latest JDK is faster, and the high-throughput garbage collector is faster than the low-latency garbage collector.

Therefore, the performance improvement brought by Java 17 is worth upgrading, and more importantly, it is free for commercial use, and it is also an LTS version.

So do you still insist on Java 8 for 10,000 years?

Leave a Reply

Your email address will not be published. Required fields are marked *