Optimize memory usage of a collection of Strings in Java

后端 未结 7 1677
有刺的猬
有刺的猬 2021-01-04 21:21

I have a large number of name - value pairs (approx 100k) that I need to store in some sort of cache (say a hash map) where the value is a string with an average of about 30

相关标签:
7条回答
  • 2021-01-04 22:14

    You could compress the strings. A 30K string should get a good compression ratio. I wrote a hack to compress large String as an exercise, but you could use a byte[] of the compressed data to store the String.

    A 30K character string will use about 60KB (2 bytes per character) so even using getBytes() is likely to be an improvement.

    0 讨论(0)
提交回复
热议问题