JDK-8352891 Performance improvements to ByteArrayOutputStream

Archie Cobbs archie.cobbs at gmail.com
Fri Apr 11 16:19:11 UTC 2025


On Fri, Apr 11, 2025 at 10:50 AM Engebretson, John <jengebr at amazon.com>
wrote:

> I would like to see JDK standard "array builders" for primitive types and
> reference types that use fixed sized (power-of-two) segments internally.
>
>
>
> I want to caution on the power-of-two idea – it leads to large objects
> faster than the current implementation, which hurts performance as well as
> max capacity.  There is value in fixed-size options but we would want
> something with a slower rate of growth.
>

Sorry if that wasn't clear - I didn't mean power-of-two exponential growth,
I meant all segments were literally fixed size, like 256 or something (or
maybe this value would be provided to the constructor). This keeps the
access to individual elements constant time.


>
>
> The "underlying problem" that I think should be addressed by some new
> internal class (or suite of classes) is the "array builder" problem. This
> is where you're doing "append, append, append, ..., use read-only
> thereafter".
>
>
>
> I would prefer targeting a few, common use cases – ByteArrayOutputStream
> is the example that got us here. Optimizing forward-only handling is an
> easy starting place and we can always add on later.
>

Fair enough - my idea is independent in the sense that it could be done
later and then retrofitted.

So I think I should probably go off and think about it more and stop
hijacking your thread :)

-Archie

-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250411/09dea45b/attachment-0001.htm>


More information about the core-libs-dev mailing list