Skip to content

Avoid extra byte array copying when downloading to memory with AsyncResponseTransformer #6348

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-d4e19d2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Avoid extra byte array copying when downloading to memory with AsyncResponseTransformer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public final class ByteArrayAsyncResponseTransformer<ResponseT> implements
@Override
public CompletableFuture<ResponseBytes<ResponseT>> prepare() {
cf = new CompletableFuture<>();
return cf.thenApply(arr -> ResponseBytes.fromByteArray(response, arr));
// Using fromByteArrayUnsafe() to avoid unnecessary extra copying of byte array. The data writing has completed and the
// byte array will not be further modified so this is safe
return cf.thenApply(arr -> ResponseBytes.fromByteArrayUnsafe(response, arr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we add a comment over here on why we are using fromByteArrayUnsafe for future references (while doing code walks)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, added comment

}

@Override
Expand Down
Loading