3 ms·
This sounds extremely valuable, if just because it requires far less tuning than interning strings. Not so long ago I had to do maintenance on a pretty large S
by hibikir 12y ago
This sounds extremely valuable, if just because it requires far less tuning than interning strings.
Not so long ago I had to do maintenance on a pretty large Swing application, still stuck on Java 6, that was built around displaying huge amounts of data, holding it all in memory, after retrieving it from some rather slow web services. The poor thing easily ended up using about a couple of gigs, mostly due to the many Strings it held, many of them pretty repetitive. While I tried to reduce the memory footprint, I couldn't just intern everything coming from the service: In Java 6, interned strings come from PermGen.
Using a hashmap to allocate everything would have been better than nothing, but the dataset had a whole lot of strings that didn't repeat themselves, so the hashmap would have been far bigger than we needed for the application.
What I ended up having to do what to figure out where the data was the most repetitive, and then intern only those strings.
I cut memory use by over 30%, but it took days of profiling, evaluating the data and making simple code changes to get there, as opposed to just a runtime flag. Now, I wonder how much better, or worse, it performs that the hashmap solution in cases like the one I faced: a few hundred strings repeated tens of thousands of times, and hundreds of thousands of strings with almost no repetition.
- blinkingled 12y agoWow,that sounds very familiar including the swing app part! Except in my case data came from database and code used StringBuffers leading to massive amounts of duplication. I had to build a COW wrapper and profile the app to find that 95% of the data was only ever read in normal use cases! Thankfully Java tooling is fairly mature - things like MAT and OQL were of great use in finding the memory hogs and leaks.