Skip to content

Commit e05bb29

Browse files
authored
Increase InternCache default max size from 100 to 200 (#1257)
* Increase InternCache default max size from 100 to 200 * ...
1 parent 1fd8cb1 commit e05bb29

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ a pure JSON library.
2222
(contributed by @pjfanning)
2323
#1252: `ThreadLocalBufferManager` replace synchronized with `ReentrantLock`
2424
(contributed by @pjfanning)
25+
#1257: Increase InternCache default max size from 100 to 200
2526

2627
2.17.1 (not yet released)
2728

src/main/java/com/fasterxml/jackson/core/util/InternCache.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public final class InternCache
2020
*<p>
2121
* One consideration is possible attack via colliding {@link String#hashCode};
2222
* because of this, limit to reasonably low setting.
23+
*<p>
24+
* Increased to 200 (from 100) in 2.18
2325
*/
24-
private final static int MAX_ENTRIES = 180;
26+
private final static int DEFAULT_MAX_ENTRIES = 280;
2527

2628
public final static InternCache instance = new InternCache();
2729

@@ -32,7 +34,7 @@ public final class InternCache
3234
*/
3335
private final ReentrantLock lock = new ReentrantLock();
3436

35-
public InternCache() { this(MAX_ENTRIES, 0.8f, 4); }
37+
public InternCache() { this(DEFAULT_MAX_ENTRIES, 0.8f, 4); }
3638

3739
public InternCache(int maxSize, float loadFactor, int concurrency) {
3840
super(maxSize, loadFactor, concurrency);
@@ -47,7 +49,7 @@ public String intern(String input) {
4749
* possible limitation: just clear all contents. This because otherwise
4850
* we are simply likely to keep on clearing same, commonly used entries.
4951
*/
50-
if (size() >= MAX_ENTRIES) {
52+
if (size() >= DEFAULT_MAX_ENTRIES) {
5153
/* As of 2.18, the limit is not strictly enforced, but we do try to
5254
* clear entries if we have reached the limit. We do not expect to
5355
* go too much over the limit, and if we do, it's not a huge problem.
@@ -56,7 +58,7 @@ public String intern(String input) {
5658
*/
5759
if (lock.tryLock()) {
5860
try {
59-
if (size() >= MAX_ENTRIES) {
61+
if (size() >= DEFAULT_MAX_ENTRIES) {
6062
clear();
6163
}
6264
} finally {

0 commit comments

Comments
 (0)