JDK-8352891 Performance improvements to ByteArrayOutputStream

Engebretson, John jengebr at amazon.com
Fri Mar 28 13:05:55 UTC 2025


Hi all!  This message is to discuss the proposal for a public class that is faster/cheaper than ByteArrayOutputStream.  Details are on the ticket [1] so I will only summarize here:
- ByteArrayOutputStream is slower than the provided alternative, and wastes memory bandwidth and allocation.
- The new alternative cannot replace ByteArrayOutputStream because BAOS exposes two implementation-specific fields.
- The problem is broadly present, and different solutions exist in Spring, Tomcat, multiple applications inside my company, and undoubtedly elsewhere.
- There are places within the JDK that will benefit from the improved performance.

My goal is to broadly distribute this new datastructure, and the JDK is an obvious place to do it.  My proposal is to publish a new public class, java.io.MemoryOutputStream extends OutputStream.  I acknowledge the difficulties in doing so.

I welcome any thoughts about the problem, solution, or deployment.  I created a draft PR [2] for discussion or questions about the proposed implementation.

1. https://bugs.openjdk.org/browse/JDK-8352891
2. https://github.com/openjdk/jdk/pull/24232
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250328/2b03f92e/attachment.htm>


More information about the core-libs-dev mailing list