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>
This commit is contained in:
seungchan
2026-06-04 09:30:36 +02:00
committed by Brian Clozel
parent 2fc99eb12f
commit 4c6194a2ad
@@ -367,7 +367,7 @@ public final class ConcurrentLruCache<K, V> {
private static final class ReadOperations<K, V> {
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<K, V> {
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);
}
}