Recently I stumbled upon this JEP 254: Compact Strings which basically targets:
Summary: Adopt a more space-efficient internal representation for strings.
From my current experience, Strings
and char[]
occupies huge percentage of total heap consumption. Like the JIRA already states:
The current implementation of the String class stores characters in a char array, using two bytes (sixteen bits) for each character. Data gathered from many different applications indicates that strings are a major component of heap usage and, moreover, that most String objects contain only Latin-1 characters. Such characters require only one byte of storage, hence half of the space in the internal char arrays of such String objects is going unused.
Considering this, I have below questions:
- How is this issue handled currently by other developers when
String
is storing only chars requiring 1 byte and also constitute a large part of heap profile? - Why this is being implemented now and have not been attempted a solution for this earlier?
- Are there already open source libraries which target solving this issue?
I have gone through basic questions like this and this regarding facts about String
which covers How StringPool
and interning String
works and Why single char in String currently occupies 2 bytes
.