Skip to content

Defensive copies of payloads trigger G1 humongous allocations #6

Description

@awelless

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions