From 4c6194a2adfbbf77dd568378df2e3b98d5cf63ce Mon Sep 17 00:00:00 2001 From: seungchan Date: Thu, 4 Jun 2026 12:08:38 +0900 Subject: [PATCH] Simplify BUFFER_COUNT in ConcurrentLruCache to a constant The detectNumberOfBuffers() method attempted to scale the read buffer count based on the number of available processors, but used Math.min(4, nextPowerOfTwo) which effectively caps the result at 4 regardless of CPU count. For systems with fewer than 3 processors, the buffer count would be reduced below 4, but this edge case adds complexity without measurable benefit. Simplify BUFFER_COUNT to a constant value of 4, removing the unnecessary CPU-detection logic. Closes gh-36872 Signed-off-by: seungchan --- .../java/org/springframework/util/ConcurrentLruCache.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java index 279e75b0ebf..33b827ca1c9 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java @@ -367,7 +367,7 @@ public final class ConcurrentLruCache { private static final class ReadOperations { - private static final int BUFFER_COUNT = detectNumberOfBuffers(); + private static final int BUFFER_COUNT = 4; private static final int BUFFERS_MASK = BUFFER_COUNT - 1; @@ -450,11 +450,6 @@ public final class ConcurrentLruCache { this.processedCount.lazySet(bufferIndex, writeCount); } - private static int detectNumberOfBuffers() { - int availableProcessors = Runtime.getRuntime().availableProcessors(); - int nextPowerOfTwo = 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(availableProcessors - 1)); - return Math.min(4, nextPowerOfTwo); - } }