RFR: 8342513: Autoboxing Overhead & Inefficient Parallel Processing

Viktor Klang vklang at openjdk.org
Thu Oct 17 19:28:23 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

@kirmaniwasif Hi!

First of all, thanks for wanting to help out!

After reviewing the proposed changes I have some comments and questions for you:

- The primitive streams (DoubleStream, IntStream, and LongStream) are designed to avoid boxing, so I'm curious as to which step has proven unable to do so, and how this PR addresses that?
- An operation changing a stream from a sequential one to a parallel one without user opting in is definitely going to be problematic. Not only does that change observable behavior, but it also is likely going to have adverse effects on performance.
- When offering a PR to improve performance, it is important to share what methodology is used for obtaining the baseline numbers and numbers indicating the performance of the proposed change. This is usually done by creating and/or running JMH-based benchmarks. And including the numbers (allocation rates, throughput, latency, etc)
- Invoking `spliterator()` on a Stream is a terminal operation, and after that has been invoked the stream has been consumed, so when I do the following on your proposed change I get an exception:


jshell> DoubleStream.of(1d, 2d).filter(d -> d > 0d).filter(d -> d > 0d).forEach(d -> System.out.println(d))
|  Exception java.lang.IllegalStateException: stream has already been operated upon or closed
|        at AbstractPipeline.<init> (AbstractPipeline.java:201)
|        at DoublePipeline.<init> (DoublePipeline.java:91)
|        at DoublePipeline$StatelessOp.<init> (DoublePipeline.java:674)
|        at DoublePipeline$8.<init> (DoublePipeline.java:358)
|        at DoublePipeline.filter (DoublePipeline.java:357)
|        at (#1:1)


Without the PR changes it works as expected:


jshell> DoubleStream.of(1d, 2d).filter(d -> d > 0d).filter(d -> d > 0d).forEach(d -> System.out.println(d))
1.0
2.0


Cheers,
√

-------------

PR Comment: https://git.openjdk.org/jdk/pull/21566#issuecomment-2420357230


More information about the core-libs-dev mailing list