Search code examples
stringjvmheap-memorychroniclechronicle-map

Are there any advantages of using Chronicle Map for java.util.String over .`intern` method for the purpose of lowering heap usage?


Intention is to reduce old gen size in order to lower gc pauses.

In my understanding Chronicle Map will store objects in native space and (starting from java 8) String#intern will do the same because interned string are in metaspace.

I was curious whenever I need to use chronicle map, or it's ok to stick with intern method.


Solution

  • ChronicleMap couldn't serve as a direct replacement of String.intern() because java.lang.String instances are always on-heap. So you won't actually win anything, even storing strings in ChronicleMap, because before using them you will deserialize them to on-heap object.

    ChronicleMap as a data structure, (not necessarily with Java implementation, maybe C++) indeed could be used for some sort of caching textual data, especially inter-process. But I suspect it is very far from what you are seeking. For example on Java side, it will require a separate value class (not String and not StringBuilder), implementing CharSequence at best.

    Also, very likely you don't need intern, but deduplication that could be much more effective, see java.lang.String Catechism talk, "Intern" section.