RFR: 8342513: Autoboxing Overhead & Inefficient Parallel Processing
xxDark
duke at openjdk.org
Thu Oct 17 20:26:33 UTC 2024
On Thu, 17 Oct 2024 16:21:29 GMT, wasif kirmani <duke at openjdk.org> wrote:
> [JDK-8342513](https://bugs.openjdk.org/browse/JDK-8342513) : Autoboxing Overhead & Inefficient Parallel Processing
This seems like an AI-generated change... Also, turning a stream into a parallel one is a recipe for disaster.
Consider this case:
var smallNumbers = new ArrayList<>(1_000_000);
var count = new AtomicInteger();
for (int i = 0; i < 3; i++) {
count.set(0);
smallNumbers.clear();
var _ = IntStream.generate(() -> {
return ThreadLocalRandom.current().nextInt(Character.MAX_VALUE);
})
.limit(9_000_000)
.parallel() // Your code calls parallel here
.filter(value -> {
// Collecting in-place to smallNumbers
if (value < 32768) {
smallNumbers.add(value);
count.incrementAndGet();
return false;
}
return true;
})
.count(); // Terminate
if (smallNumbers.size() != count.get()) {
throw new IllegalStateException();
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21566#issuecomment-2420485311
More information about the core-libs-dev
mailing list