From 2a4a6dc908284d94c55b5b62ba114d0e25434cea Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 19 Apr 2024 17:50:58 -0700 Subject: [PATCH] Fix #1256: revert #1117, default recycler pool again `threadLocalPool()` (for 2.17.1+) (#1267) --- release-notes/VERSION-2.x | 2 ++ .../jackson/core/util/JsonRecyclerPools.java | 8 +++++--- src/test/java/perf/RecyclerPoolTest.java | 14 +++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 5c29854ff0..5abff8a45b 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,8 @@ a pure JSON library. #1241: Fix `NumberInput.looksLikeValidNumber()` implementation (contributed by @pjfanning) +#1256: Revert #1117: change default recycler pool back to `threadLocalPool()` + for 2.17.1 2.17.0 (12-Mar-2024) diff --git a/src/main/java/com/fasterxml/jackson/core/util/JsonRecyclerPools.java b/src/main/java/com/fasterxml/jackson/core/util/JsonRecyclerPools.java index 4547b2c36b..bf724294cc 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/JsonRecyclerPools.java +++ b/src/main/java/com/fasterxml/jackson/core/util/JsonRecyclerPools.java @@ -19,14 +19,16 @@ public final class JsonRecyclerPools { /** * Method to call to get the default recycler pool instance: - * as of Jackson 2.17 this is same as calling - * {@link #newLockFreePool()}; earlier + * as of Jackson 2.17.x and earlier (except for 2.17.0) this is same as calling + * {@link #threadLocalPool()} -- 2.17.0 temporarily had this call + * {@link #newLockFreePool()} (but reverted due to problems reported). + * Will likely be changed in 2.18.0 to something else. * * @return the default {@link RecyclerPool} implementation to use * if no specific implementation desired. */ public static RecyclerPool defaultPool() { - return newLockFreePool(); + return threadLocalPool(); } /** diff --git a/src/test/java/perf/RecyclerPoolTest.java b/src/test/java/perf/RecyclerPoolTest.java index 5165bfbf14..d0dc967d5a 100644 --- a/src/test/java/perf/RecyclerPoolTest.java +++ b/src/test/java/perf/RecyclerPoolTest.java @@ -24,7 +24,7 @@ */ public class RecyclerPoolTest { - final static int THREAD_COUNT = 100; + final static int THREAD_COUNT = 200; final static int RUNTIME_SECS = 60; @@ -100,7 +100,8 @@ void testUntil(JsonFactory jsonF, long endTimeMsecs, int threadId, AtomicLong calls) { final Random rnd = new Random(threadId); - final byte[] JSON_INPUT = "\"abc\"".getBytes(StandardCharsets.UTF_8); + final byte[] JSON_INPUT = "42 " + .getBytes(StandardCharsets.UTF_8); while (System.currentTimeMillis() < endTimeMsecs) { try { @@ -144,7 +145,6 @@ private void _testWrite(JsonFactory jsonF) throws Exception StringWriter w = new StringWriter(16); JsonGenerator g = jsonF.createGenerator(w); g.writeStartArray(); - g.writeString("foobar"); g.writeEndArray(); g.close(); } @@ -154,15 +154,15 @@ public static void main(String[] args) throws Exception RecyclerPoolTest test = new RecyclerPoolTest(THREAD_COUNT); List results = Arrays.asList( test.testPool(JsonFactory.builder() - .recyclerPool(JsonRecyclerPools.newConcurrentDequePool()) + .recyclerPool(JsonRecyclerPools.newLockFreePool()) .build(), - RUNTIME_SECS), + RUNTIME_SECS * 1000), test.testPool(JsonFactory.builder() - .recyclerPool(JsonRecyclerPools.newBoundedPool(THREAD_COUNT - 5)) + .recyclerPool(JsonRecyclerPools.newConcurrentDequePool()) .build(), RUNTIME_SECS), test.testPool(JsonFactory.builder() - .recyclerPool(JsonRecyclerPools.newLockFreePool()) + .recyclerPool(JsonRecyclerPools.newBoundedPool(THREAD_COUNT - 5)) .build(), RUNTIME_SECS) );