3 ms·
I'm excited to try Java9. I have an app that holds alot of strings in memory. I'm curious/hoping the 'compact strings' feature makes a noticeable difference o
by stevehiehn 9y ago
I'm excited to try Java9. I have an app that holds alot of strings in memory. I'm curious/hoping the 'compact strings' feature makes a noticeable difference on memory usage.
- shock 9y agoIf you have many strings that are the same you can use String interning[0] to reduce the memory usage. 0 - http://java-performance.info/string-intern-in-java-6-7-8/ http://java-performance.info/string-intern-in-java-6-7-8/
- nalllar 9y agoYou will probably see better performance if you write your own string deduplication. https://shipilev.net/jvm-anatomy-park/10-string-intern/ https://shipilev.net/jvm-anatomy-park/10-string-intern/ > In almost every project we were taking care of, removing String.intern() from the hotpaths, or optionally replacing it with a handrolled deduplicator, was the very profitable performance optimization. Do not use String.intern() without thinking very hard about it, okay?
- stevehiehn 9y agoThat's not going to help my current situation, but either way, thanks, that's really good to know.
- hyperpape 9y agoThey're really different issues. Deduplication reduces the memory consumption of duplicate strings. Compact strings reduce the memory consumption of ascii strings, regardless of whether they're unique or mostly duplicates. So depending on your situation, you could want either, both, or neither. There is some overlap, however. If you have a lot of ascii strings but also a high level of duplication, either approach will save some memory, but if deduplication by itself saves x bytes, and compact strings saves y, using both will save a lot less than x + y bytes. And, like the later poster says, don't use String.intern() for deduplication.
- shock 9y ago> They're really different issues. They're different fixes for the same problem: high memory usage. Depending on the situation you can use one or both, as you say.
- zipperhead 9y agoIsn't this already in java 8? As of update 20 you can set -XX:+UseStringDeduplication if you are using the new -XX:+UseG1GC garbage collector.