From 5e3e0ce12cc2f9730e2fa779eaebd136953be4a1 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 25 Jan 2024 16:27:34 -0800 Subject: [PATCH] Performance improvements (#4850) --- .../next-release/bugfix-AWSSDKforJavav2-8b416ff.json | 6 ++++++ .../next-release/feature-AWSSDKforJavav2-9014236.json | 6 ++++++ .../auth/credentials/ProfileCredentialsProvider.java | 6 +++--- .../chunkedencoding/ChunkedEncodedInputStream.java | 11 ++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .changes/next-release/bugfix-AWSSDKforJavav2-8b416ff.json create mode 100644 .changes/next-release/feature-AWSSDKforJavav2-9014236.json diff --git a/.changes/next-release/bugfix-AWSSDKforJavav2-8b416ff.json b/.changes/next-release/bugfix-AWSSDKforJavav2-8b416ff.json new file mode 100644 index 000000000000..a310819cec27 --- /dev/null +++ b/.changes/next-release/bugfix-AWSSDKforJavav2-8b416ff.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "AWS SDK for Java v2", + "contributor": "", + "description": "Fixed bug where the ProfileCredentialsProvider would re-read the credentials file with each request by default." +} diff --git a/.changes/next-release/feature-AWSSDKforJavav2-9014236.json b/.changes/next-release/feature-AWSSDKforJavav2-9014236.json new file mode 100644 index 000000000000..3be2d9de5269 --- /dev/null +++ b/.changes/next-release/feature-AWSSDKforJavav2-9014236.json @@ -0,0 +1,6 @@ +{ + "type": "feature", + "category": "AWS SDK for Java v2", + "contributor": "", + "description": "Improved performance of chunk-encoded streaming uploads, like S3's PutObject." +} diff --git a/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.java b/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.java index 13cbdd5f57b1..95d6bb88afb4 100644 --- a/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.java +++ b/core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.java @@ -71,9 +71,9 @@ private ProfileCredentialsProvider(BuilderImpl builder) { try { selectedProfileName = Optional.ofNullable(builder.profileName) .orElseGet(ProfileFileSystemSetting.AWS_PROFILE::getStringValueOrThrow); - - selectedProfileSupplier = Optional.ofNullable(builder.profileFile) - .orElseGet(() -> builder.defaultProfileFileLoader); + selectedProfileSupplier = + Optional.ofNullable(builder.profileFile) + .orElseGet(() -> ProfileFileSupplier.fixedProfileFile(builder.defaultProfileFileLoader.get())); } catch (RuntimeException e) { // If we couldn't load the credentials provider for some reason, save an exception describing why. This exception diff --git a/core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/internal/signer/chunkedencoding/ChunkedEncodedInputStream.java b/core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/internal/signer/chunkedencoding/ChunkedEncodedInputStream.java index dacabafbf4e1..16bbdd980da6 100644 --- a/core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/internal/signer/chunkedencoding/ChunkedEncodedInputStream.java +++ b/core/http-auth-aws/src/main/java/software/amazon/awssdk/http/auth/aws/internal/signer/chunkedencoding/ChunkedEncodedInputStream.java @@ -77,11 +77,20 @@ public static Builder builder() { @Override public int read() throws IOException { + return currentChunk().stream().read(); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + return currentChunk().stream().read(b, off, len); + } + + private Chunk currentChunk() throws IOException { if (currentChunk == null || !currentChunk.hasRemaining() && !isFinished) { currentChunk = getChunk(inputStream); } - return currentChunk.stream().read(); + return currentChunk; } /**