Skip to content

AsyncRequestBody.fromBytes will copy the given buffer twice #1877

Closed
@injeniero

Description

@injeniero

Calling AsyncRequestBody.fromBytes will cause your byte array to be copied twice.

Describe the bug

AsyncRequestBody.fromBytes body is:

static AsyncRequestBody fromBytes(byte[] bytes) {
    return new ByteArrayAsyncRequestBody(Arrays.copyOf(bytes, bytes.length));
}

Which does a first copy using Arrays.copyOf then the constructor of ByteArrayAsyncRequestBody

public ByteArrayAsyncRequestBody(byte[] bytes) {
        this.bytes = bytes.clone();
    }

Which clones the given byte array again.

Expected Behavior

Calling AsyncRequestBody.fromBytes should not duplicate the given array twice. Ideally, you could provide a second function to avoid copying at all: AsyncRequestBody.fromBytesNoCopy

Context

We are running a high performance messaging service and we are saving data to S3 directly from the in memory data structures. We serialize them and then give the byte array to upload to S3.

Your Environment

  • AWS Java SDK version used: 2.13.30
  • JDK version used: java11
  • Operating System and version: Docker linux Ubuntu 18.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions