Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6347575

FileImageInputStream.readInt() and similar methods are inefficient

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 6
    • Component/s: client-libs
    • Subcomponent:
    • Introduced In Build:
      1.4
    • Introduced In Version:
    • Resolved In Build:
      b63
    • CPU:
      generic
    • OS:
      solaris_9

      Description

      In the evaluation of 6215304, an observation was made that the PNGImageReader seemed
      to be making a large number of calls to ImageInputStream.read(), in other words,
      reading a single byte at a time. For a FileImageInputStream, this corresponds to
      a JNI downcall and a system call to read a single byte from a RandomAccessFile object.
      It turns out that the source of these frequent read() calls was in PNGImageReader's
      readHeader() and readMetadata() methods. In particular, these methods make a number
      of calls to methods like ImageInputStream.readInt(). Digging further, I found that
      ImageInputStreamImpl.readInt(), as currently implemented, calls read() 4x, and then
      composes the 4 bytes to form a single int value.

      Experiments show that calling read() 4x is much more expensive than making a single
      call to read(byte[]) with a cached byte array. Interestingly, this (and related
      changes) have a profound impact on performance of reading small PNG and other images.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                campbell Christopher Campbell (Inactive)
                Reporter:
                campbell Christopher Campbell (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: