pjfanning opened a new pull request, #1190: URL: https://github.com/apache/pekko-http/pull/1190
I got Claude AI to analyse this project and its analysis exaggerated the memory impact here. This change does help a bit but not as much as the original analysis indicated. The existing code is already pretty strong in its protection against memory overallocation. File: http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala Replaced ByteArrayOutputStream with ByteStringBuilder in the inflate method of InflaterFlow: 1. ByteArrayOutputStream(1024) → ByteStringBuilder with sizeHint: The old code started with a 1024-byte buffer and doubled on each resize, creating temporary arrays. The new code pre-sizes to min(maxAllocation, 128KB), avoiding excessive reallocations for large messages while not over-allocating for small ones. 2. output.write(buffer, 0, count) → output.putBytes(buffer, 0, count): Uses the Pekko ByteStringBuilder API. 3. ByteString.fromArrayUnsafe(output.toByteArray) → output.result(): The old toByteArray() created a full copy of the internal buffer. ByteStringBuilder.result() avoids this extra copy. Net effect: Reduces peak memory per decompressed message from ~3x the maxAllocation limit to ~2x (eliminating the extra toByteArray() copy). All 45 existing WebSocket tests pass, including the two max-allocation limit tests. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
