-
Notifications
You must be signed in to change notification settings - Fork 977
Eliminate lambda indirection overhead in DynamoDB Enhanced Client #6591
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
base: master
Are you sure you want to change the base?
Conversation
|
|
Closing because testing on remote produces inconclusive results. |
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
|
Re-opening with new metrics. Testing on remote host: |
| this.attributeType = attributeType; | ||
| } | ||
|
|
||
| AttributeValue getAttributeValue(T item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be private?
| @@ -27,33 +27,40 @@ | |||
| import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | |||
|
|
|||
| @SdkInternalApi | |||
| public final class ResolvedImmutableAttribute<T, B> { | |||
| public final class ResolvedImmutableAttribute<T, B, R> { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three type parameters starts to feel like a lot to keep track of with just single letter type names. We should at least documment in comments what these are.




Motivation and Context
The DynamoDB Enhanced Client v2 shows significant performance regression compared to v1 DynamoDB Mapper, with 32-98% slower operations across all operations. One theory was that lambda allocation overhead in
ResolvedImmutableAttribute.attributeGetterMethod()is a key bottleneck affecting all operations in the serialization hot path.The change refactors how attribute values are extracted during serialization by replacing an inline lambda expression with a method reference to a dedicated instance method. Profiling shows this reduces allocations of iterator and builder objects, with
LinkedHashMap$LinkedEntryIteratorallocations dropping 44% andDefaultDynamoDbExtensionContext$Builderallocations dropping 30%. The method reference approach appears to allow the JVM to optimize the call path more effectively, though the exact mechanism linking the code change to these specific allocation reductions is not fully clear from profiling data.Changes
Before:
Put with SMALL data set
After:
Put with SMALL data set (lambda$create is eliminated)
Results
running existing benchmarks for
test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/enhanced/dynamodbJava 21
Java 17
Java 8
JFR Profiling (Get TINY benchmark):
Allocation Impact: