Sunday 21 February 2016

Learn about JDK9 Compact Strings (Video review Charlie Hunt)

JDK 9 introduces a new feature called Compact Strings.  Given the ubiquity of Strings in Java programs I feel that this is a really important change that needs to be understood by all Java developers.

In this video Charlie Hunt explains the history and implementation of this new feature.  The video is not actually about Compact Strings. Compact Strings are only introduced as a case study to explain how with a lot of work, the three legged stool of, latency, throughput and memory footprint can all be improved together.

If you have the time I definitely recommend watching the whole video - although the actual part on Compact Strings start at 26:24.

If you want a 5 minute overview here are the highlights:

  • String density (JEP 254 Compact Strings) is a feature of JDK 9.
  • Aims were to reduce memory footprint without affecting any performance - latency or throughput as well maintaining full backward compatibility.
  • JDK 6 introduced compressed strings but this was never brought forward into later JVMs.  This is a complete rewrite.
  • To work out how much memory could be saved 960 disparate java application heap dumps were analysed.
  • Live data size of the heap dumps were between 300MB and 2.5GB.
  • char[] consumed between 10% and 45% of the live data
  • vast majority of chars were only one byte in size (i.e. ASCII) 
  • 75% of the char arrays were 35 chars or smaller
  • On average reduction in application size would be 5-15% (reduction in char[] size about 35-45% because of header size)
  • The way it will be implemented is that if all chars in the String use only 1 byte (the higher byte is 0) then a byte[] will be used rather than char[] (IS0-8859-1/Latin1 encoding).  There will a leading bye to indicate which encoding was used.
  • UTF8 not used because it supports variable length chars and is therefore not performant for random access.
  • private final byte coder on the String indicates the encoding.  Note the room to support many more encodings in the future.
  • For all 64 bit JVMs no extra memory was needed for the extra field because of the 'dead' space needed for 8 byte object alignment.
  • Throughput doesn't suffer as tested with 400 JMH benchmarks available online.
  • The reason for this is that String is highly optimized in that there 55 specific JVM features for String alone.
  • Latency also improved tested with industry benchmark SPECjbb2015 also regression tested on SPECjbb2005
  • Feature can be enabled and disabled with -XX:+CompactStrings but will be enabled by default.




25 comments:


  1. I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.
    Java Training in Chennai

    ReplyDelete
  2. It is useful information, this Compact string type will give more performance like python provided.


    Java Training in Chennai | JEE Training in Chennai | Spring Training in Chennai

    ReplyDelete
  3. This information is impressive; I am inspired with your post writing style & how continuously you describe this jdk9 concept. Thanks for sharing.. HP LR Training in Chennai | ALM Training in Chennai | UFT Training in Chennai

    ReplyDelete
  4. It is useful information, this Compact string type will give more performance like python provided. Executive Protection

    ReplyDelete
  5. You can also buy cheap reseller hosting in Pakistan from us. Softhof providing low cost web hosting in Pakistan, both cheap and reliable domain registration and webhosting services to our many satisfied customers. Softhof is one of the famous and oldest web hosting providers. Softhof offers best web hosting services in Lahore Pakistan, you can buy free domain with web hosting services from us.
    Web Hosting in Pakistan

    ReplyDelete
  6. Today, encouraged by this post I decided to give a try to Java 10 on the software my company is working on. Roughly speaking, it's an interpreter of exotic programming languages that is not particularly optimized and contains a lot of strings inside.

    Surprisingly, Java 10 turned out to be A LOT slower than Java 1.8_171, and also eats a lot of memory. On hardest test, it eats 15% more total memory and is 19% slower!

    Testing was done on Linux subsystem for Win 10, benchmarking performed with `/usr/bin/time -v `.

    Why so?

    ReplyDelete
    Replies
    1. P.S. hardest test runs continuously with 100% CPU usage on one thread for 20 min.

      Delete
  7. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    Java Training in Chennai
    Java course in Chennai
    Hadoop Training in Chennai
    Python Training in Chennai
    Java Training in Porur
    Java Training in Adyar
    Java Training in Tnagar

    ReplyDelete
  8. Thank you very much for a complete example. I have been struggling with this for two days and all other examples were either incorrect or incomplete. thanks for ur efforts and work
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  9. Battle through history and build up a great empire! Start play play forge of empires online at this point!

    ReplyDelete
  10. I am very impressed to see this blog thanks for giving this very useful information.
    python best tutorial
    free python tutorial

    ReplyDelete
  11. Searching for a career in cybersecurity?

    Look no further than Indian Cyber Security Solutions for Certified Ethical Hacking Training. Our training programme is created to provide you the theoretical understanding, hands-on expertise, and certification necessary to be successful in this highly demanded industry.

    Our training is meticulously crafted and taught by seasoned experts with a wealth of experience. You'll learn the latest techniques, tools, and methodologies used by professional ethical hackers while gaining hands-on experience through real-world scenarios. Sharpen your problem-solving abilities and unleash your potential as a certified ethical hacker.

    Join us today to embark on a transformative journey towards an exciting career in cybersecurity!

    ReplyDelete
  12. Take a step towards a rewarding career in cybersecurity with our Ethical Hacking
    training course in Bangalore. Acquire the knowledge and skills needed to identify vulnerabilities and safeguard critical information.

    ReplyDelete
  13. Transform your passion for cybersecurity into a rewarding career with our Ethical hacking Training in Kolkata. Our comprehensive curriculum covers the latest industry trends and best practices, empowering you to protect organizations from cyber threats effectively.

    ReplyDelete