Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-12081

ShallowEtagHeaderFilter should use a more efficiently dynamically resizing buffer than ResizableByteArrayOutputStream

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.0.6
    • Fix Version/s: 4.2 RC1
    • Component/s: Web
    • Last commented by a User:
      true

      Description

      ShallowEtagHeaderFilter buffers the response in ResizableByteArrayOutputStream. When it needs to grows the response, it uses ResizableByteArrayOutputStream.resize(int):
      https://github.com/spring-projects/spring-framework/blob/v4.0.6.RELEASE/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java#L245
      https://github.com/spring-projects/spring-framework/blob/v4.0.6.RELEASE/spring-core/src/main/java/org/springframework/util/ResizableByteArrayOutputStream.java#L64

      ResizableByteArrayOutputStream then creates a new buffer, copies the old buffer into the new buffer, then (implicitly) releases the old buffer.

      It would be more efficient to use a linked list of buffers. The resize operation would create a new empty buffer and add it to the linked list of buffers. This approach results in less copying so less overall memory use (reducing the frequently of problems such as SPR-10855 when due to buffer resizing).

      For an example of this approach in use today, see Grails' StreamCharBuffer: https://github.com/grails/grails-core/blob/355a031bfacbdc94c60b4a8fe4131a500c8833cb/grails-encoder/src/main/groovy/org/grails/buffer/StreamCharBuffer.java Note that this approach is also in use in MyFaces, see https://issues.apache.org/jira/browse/MYFACES-3450

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bclozel Brian Clozel
              Reporter:
              candrews Craig
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 25 weeks, 1 day ago