Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase InternCache default max size from 100 to 200 #1257

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ a pure JSON library.
(contributed by @pjfanning)
#1252: `ThreadLocalBufferManager` replace synchronized with `ReentrantLock`
(contributed by @pjfanning)
#1257: Increase InternCache default max size from 100 to 200

2.17.1 (not yet released)

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/fasterxml/jackson/core/util/InternCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public final class InternCache
*<p>
* One consideration is possible attack via colliding {@link String#hashCode};
* because of this, limit to reasonably low setting.
*<p>
* Increased to 200 (from 100) in 2.18
*/
private final static int MAX_ENTRIES = 180;
private final static int DEFAULT_MAX_ENTRIES = 280;

public final static InternCache instance = new InternCache();

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

public InternCache() { this(MAX_ENTRIES, 0.8f, 4); }
public InternCache() { this(DEFAULT_MAX_ENTRIES, 0.8f, 4); }

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