Why is string.intern() so slow?

前端 未结 4 898
萌比男神i
萌比男神i 2020-12-13 00:50

Before anyone questions the fact of using string.intern() at all, let me say that I need it in my particular application for memory and performance reasons.

4条回答
  •  遥遥无期
    2020-12-13 01:01

    This article discusses the implementation of String.intern(). In Java 6 and 7, the implementation used a fixed size (1009) hashtable so as the number entries grew, the performance became O(n). The fixed size can be changed using -XX:StringTableSize=N. Apparently, in Java8 the default size is larger but issue remains.

提交回复
热议问题