Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New feature in Java 8u20 - string deduplication  RSS feed

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16007
87
Android IntelliJ IDE Java Scala Spring
  • Likes 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As developers we often only notice the new language features whenever a new Java version comes out, but a lot of improvements are done under the covers. The JVM has a lot of sophisticated tricks to make your Java programs run fast.

In Java 8 update 20 a new experimental feature was added, string deduplication. Since it's experimental you have to enable it explicitly before it works. For some applications it can lower memory usage.

I found this blog post that describes it: String Deduplication – A new feature in Java 8 Update 20.

(Not written by anyone I have any connection with, I just found it interesting to learn about this new feature).

The Java compiler itself does something similar with string literals (the famous string pool about which so many people are asking questions about on the forum), but this is about a similar feature which works at runtime, not at compile time.
 
Claude Moore
Ranch Hand
Posts: 874
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your hint !
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for sharing the details. Very helpful.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
The Java compiler itself does something similar with string literals (the famous string pool about which so many people are asking questions about on the forum), but this is about a similar feature which works at runtime, not at compile time.

I am struggling a bit to understand this conceptually. How is it different from the string pool? (which is also runtime and not compile time)
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Jesper de Jong wrote:
The Java compiler itself does something similar with string literals (the famous string pool about which so many people are asking questions about on the forum), but this is about a similar feature which works at runtime, not at compile time.

I am struggling a bit to understand this conceptually. How is it different from the string pool? (which is also runtime and not compile time)

Well, the distinction of compile time vs. run time is misleading here I think, since some aspects of the string pool are identified at compile time, and others are determined at run time. A more useful thing to focus on is this: the string pool works only on string literals plus any string on which the intern() method has been called. Whereas string de-duplication works on all strings. Eventually, at least - given enough time. Read the article for further details though.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very interesting feature. I had my reservations before reading the article, because I immidiately thought of how String interning works and the cost associated with it. Having that applied to all String instances as standard didn't strike me as a terrific idea. Thankfully this features works differently, only deduplicating the char array and that at asynchronously at garbage collection. That seems a lot more sane
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!