Closed
Description
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