Change A1: Tell ByteArrayOutputStream required capacity #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The byte array in
ByteArrayOutputStream
doubles in size every time capacity is exhausted - for an object just over 1GB in size, the buffer will eventually grow to 2GB in size - unnecessarily large, and involving a lot of array copies (ceil(log_2 (N/32))
copies).https://github.com/openjdk/jdk/blob/218829e0a2a3ae5599b81733df53557966392033/src/java.base/share/classes/java/io/ByteArrayOutputStream.java#L100-L101
If we just tell the Content Length to initialise the
ByteArrayOutputStream
with a byte array of the right size, the array will never get bigger than it needs to be - and it won't have do array-resizing either.Required RAM: 934 MB