Will your applications run faster with Java 9, 10, 11?

Posted on: February 28, 2019 by Ioannis Kolaxis

Are you still running your software applications on Java 8? Since Java 9, there have been several enhancements on how Strings are being handled, promising to improve the performance of your applications.

Storing Strings

If you examine the memory being used by your Java application, you will most likely notice that a significant amount of the heap is allocated by String objects.

Up to Java 8, each String is represented internally as a char[] (that is a char array).

The char data type is a single Unicode character that takes up 2 bytes of memory. It has a minimum value of 'u0000' (=0) and a maximum value of 'uffff' (=65535).

When we store a Unicode character, such as the Greek character 'α' (='u03b1'), then we are truly making use of both bytes being allocated for that char.

However, when we store a Latin character, such as 'a' (='u0061'), then the first byte allocated for that char is filled with zeros and is thus being effectively unused.

Wouldn't it be great if Java didn't allocate 2 bytes for each Latin character, but allocated only 1 byte instead?

In Java 9, the String class has been changed to store characters in a byte[] (instead of a char[]). This change in the underlying data structure of String allows a fine grained allocation of memory, depending on the type of characters:

  • for Strings containing Unicode characters, 2 bytes are being allocated for each character, as previously.
  • for Strings containing only Latin characters, 1 byte is allocated for each character, thus saving memory compared to previous releases of Java.

Concatenating Strings

Up to Java 8, the Java compiler recognizes any String concatenations in the source code, and translates them into chains of StringBuilder::append.

Since Java 9, each String concatenation is translated into a call to invokedynamic, as described in JDK Enhancement Proposal 280.

There are several String concatenation strategies available in Java 9, with each one of them employing a different technique to compute the size of the resulting/concatenated String. One of the strategies that stands out for its performance is MH_INLINE_SIZED_EXACT, which takes advantage of private Java APIs to perform the String concatenation.

Performance Improvement

The allocation rate is a key performance metric in Java applications; it is the amount of memory allocated per time unit, and it is typically measured in MB/sec.

Thanks to the reduced memory footprint of String objects since Java 9, your applications are expected to have a lower allocation rate; this means that the Garbage Collector will be called less frequently to clean the memory. Given that the Garbage Collector pauses your applications while it is cleaning the memory, you will likely experience a decrease in the frequency and/or the duration of pauses for your applications. It is therefore assumed that your applications will have a higher throughput, and lower latency in Java 9, 10, 11.

As stated here, "footprint and performance improvements up to 10%" have been measured for several applications in Java 9.

How much faster will your applications run with Java9, 10, 11? There is only one way to find out: download the latest version of Java and measure the performance of your applications!


If you are interested in finding out more details about the String-related enhancements that were introduced in Java 9, please check the following resources:

  1. JEP 254: Compact Strings
  2. JEP 280: Indify String Concatenation
  3. Video: Aleksey Shipilëv presents the work done in JDK 9 for JEP 254, and JEP280
  4. Video: Aleksey Shipilëv demonstrates the performance of JDK 9 with JEP 254, and JEP280

Share this blog article

  • Share on Linked In

About Ioannis Kolaxis
Software Architect, Atos Distinguished Expert
Ioannis Kolaxis is a Software Architect, building Next Generation 911/112 software solutions that empower emergency services to save lives. He has been previously developing software for the banking industry in IBM and the telecommunications sector in SIEMENS. He enjoys sharing his experience with the software development community, speaking at international conferences, such as Oracle Code One 2019. He was awarded by Atos the title of “Distinguished Expert” as a recognition of his technical expertise & professional accomplishments. He is an inventor, having filed several patents & having won the 1st prize award at Atos Innovation Week 2020 for coming up with the most innovative idea. He is passionate about new technologies and likes to share his thoughts on his blog & YouTube channel about how technology can transform our lives. Follow him on Twitter to be updated about his work.

Follow or contact Ioannis