Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-97

Trivial performance improvements to ByteArrayOutputStream

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.2
    • 1.3
    • Streams/Writers
    • None

    Description

      Found a few trivial ways to improve performance in ByteArrayOutputStream by fast paths:

      • write(int) does not have to be synchronized
      • write(byte[]..) does not have to be synchronized as a whole either; it's enough to synchonize the code that follows the first paramter-checking if-then statement (so parameter checks can pop out quickly)
      • toByteArray() could just check if count == 0 and quickly return an empty static final byte[] instead of returning a new zero-sized one, doing useless System.arraycopy() etc.

      A somewhat more involved optimization would be to implement write(int) without the new byte[1] since just poking the byte into the right page is going to be much faster than what happens in write(byte[]..); I'll see if I can do a patch for that.

      Attachments

        1. BAOS.patch
          5 kB
          Holger Hoffstätte

        Activity

          People

            scolebourne Stephen Colebourne
            h2o Holger Hoffstätte
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: