Skip to content

Commit 4c6194a

Browse files
s-chan-obclozel
authored andcommitted
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 <s24041@gsm.hs.kr>
1 parent 2fc99eb commit 4c6194a

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ boolean isActive() {
367367

368368
private static final class ReadOperations<K, V> {
369369

370-
private static final int BUFFER_COUNT = detectNumberOfBuffers();
370+
private static final int BUFFER_COUNT = 4;
371371

372372
private static final int BUFFERS_MASK = BUFFER_COUNT - 1;
373373

@@ -450,11 +450,6 @@ private void drainReadBuffer(int bufferIndex) {
450450
this.processedCount.lazySet(bufferIndex, writeCount);
451451
}
452452

453-
private static int detectNumberOfBuffers() {
454-
int availableProcessors = Runtime.getRuntime().availableProcessors();
455-
int nextPowerOfTwo = 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(availableProcessors - 1));
456-
return Math.min(4, nextPowerOfTwo);
457-
}
458453
}
459454

460455

0 commit comments

Comments
 (0)