• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New feature in Java 8u20 - string deduplication

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your hint !
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for sharing the details. Very helpful.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I AM MIGHTY! Especially when I hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic