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

Improve performance of InflaterOutputStream.write()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8, 11, 15
    • performance
    • None

      InflaterOutputStream has an internal buffer which is used for the inflated data. This buffer can be configured to a custom size (the default is 512 bytes) by using the specialized "InflaterOutputStream(OutputStream out, Inflater infl, int bufLen)" constructor. A bigger buffer, results in fewer native calls to "write()" on the associated OutputStream and better overall performance.

      Unfortunately "InflaterOutputStream.write(byte[] b, int off, int len)" unnecessarily chunks its byte input buffer "b" into pieces of maximum 512 bytes before feeding them to the underlying Inflater. This unnecessarily increases the number of native calls to Inflater.inflate() and limits the benefit of the configurable internal buffer to ~(512 * compression-ratio).

      Instead, we could easily pass the complete input buffer "b" as input to the underlying Inflater. This simplifies the code and results in up to ~25% performance improvements for bigger internal buffers (see attached JMH benchmark).

            simonis Volker Simonis
            simonis Volker Simonis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: