Skip to content

AsyncRequestBody.fromBytes will copy the given buffer twice #1877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
injeniero opened this issue Jun 5, 2020 · 0 comments · Fixed by #1888
Closed

AsyncRequestBody.fromBytes will copy the given buffer twice #1877

injeniero opened this issue Jun 5, 2020 · 0 comments · Fixed by #1888
Labels
bug This issue is a bug.

Comments

@injeniero
Copy link

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
@injeniero injeniero added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 5, 2020
dagnir added a commit to dagnir/aws-sdk-java-v2 that referenced this issue Jun 10, 2020
@dagnir dagnir mentioned this issue Jun 10, 2020
13 tasks
@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Jun 11, 2020
aws-sdk-java-automation added a commit that referenced this issue Dec 13, 2021
…2449abfde

Pull request: release <- staging/909f7b68-13f6-43b1-91be-f7c2449abfde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants