<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Supporting what Alan said. Would love to see a static factory for
      a non-synchronized byte-array backed OutputStream, like
      `OutputStream::newByteArrayOutputStream`. John, if you like we can
      team up for authoring this, I have free capacity.<br>
    </p>
    <div class="moz-cite-prefix">Am 29.03.2025 um 09:33 schrieb Alan
      Bateman:<br>
    </div>
    <blockquote type="cite"
      cite="mid:d9fdd1b1-67e5-45d7-b7a6-a07ed771bba3@oracle.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      On 28/03/2025 13:05, Engebretson, John wrote:<br>
      <blockquote type="cite"
        cite="mid:8721e7784793451187c5b6099eb37756@amazon.com">
        <meta name="Generator"
          content="Microsoft Word 15 (filtered medium)">
        <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}div.WordSection1
        {page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
        <div class="WordSection1">
          <p class="MsoNormal">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:<o:p></o:p></p>
          <p class="MsoNormal">- ByteArrayOutputStream is slower than
            the provided alternative, and wastes memory bandwidth and
            allocation.<o:p></o:p></p>
          <p class="MsoNormal">- The new alternative cannot replace
            ByteArrayOutputStream because BAOS exposes two
            implementation-specific fields.<o:p></o:p></p>
          <p class="MsoNormal">- The problem is broadly present, and
            different solutions exist in Spring, Tomcat, multiple
            applications inside my company, and undoubtedly elsewhere.<o:p></o:p></p>
          <p class="MsoNormal">- There are places within the JDK that
            will benefit from the improved performance.<o:p></o:p></p>
          <p class="MsoNormal"><o:p> </o:p><br>
          </p>
        </div>
      </blockquote>
      There are many possible directions and APIs that could be explored
      here, lots of fun.<br>
      <br>
      The JBS issue seems to all about BAOS performance, esp. due to it
      maintaining a contiguous array and needing to resize. Rather than
      introduce a subclass into the API then maybe you instead explore
      adding a static factory that returns a BAOS with a different
      implementation. For a long time we've been mulling over adding a
      factory method to get a BAOS that isn't thread safe (the
      undocumented synchronization dates from JDK 1.0 and too risky to
      change after 30 years of usage). It would also be feasible to have
      BOAS use a different implementation when used directly vs. when
      subclassed although that wouldn't be pretty.<br>
      <br>
      -Alan<br>
    </blockquote>
  </body>
</html>