Message constructor and getPayload() make defensive copies of large payloads, causing G1 humongous allocations
Describe the bug
Message makes two unconditional defensive copies of the payload byte array:
// Message.java — constructor
this.payload = requireNonNull(payload, "payload").clone();
// Message.java — getter
public byte[] getPayload() {
return payload.clone();
}
On a dev machine (8 vCPUs, 18 GB heap) for payloads larger than ~8 MB (half of a 16 MB G1 region), each clone is a G1 humongous allocation and may directly trigger a GC cycle. Humongous allocations degrade the overall system performance.
Possible Solution
Should Message class has no-copy constructor and payload getter using which will reduce unnecessary memory allocations?
Additional details
There are more allocations, e.g. array allocation during decoding or underlying BAOS array resizing. But these were not present on JFR recordings.
Library version used
aws-eventstream 1.0.1 (via aws-sdk 2.41.24)
JDK version used
21.0.10
Operating System and version
Linux
Message constructor and getPayload() make defensive copies of large payloads, causing G1 humongous allocations
Describe the bug
Messagemakes two unconditional defensive copies of the payload byte array:On a dev machine (8 vCPUs, 18 GB heap) for payloads larger than ~8 MB (half of a 16 MB G1 region), each clone is a G1 humongous allocation and may directly trigger a GC cycle. Humongous allocations degrade the overall system performance.
Possible Solution
Should
Messageclass has no-copy constructor and payload getter using which will reduce unnecessary memory allocations?Additional details
There are more allocations, e.g. array allocation during decoding or underlying BAOS array resizing. But these were not present on JFR recordings.
Library version used
aws-eventstream 1.0.1(viaaws-sdk 2.41.24)JDK version used
21.0.10Operating System and version
Linux