-
Notifications
You must be signed in to change notification settings - Fork 951
Serialization optimization for DDB enhanced Client #6507
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
Conversation
c0c396a to
6b2036a
Compare
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/document/StrategyJsonSerializer.java
Outdated
Show resolved
Hide resolved
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/document/StrategyJsonSerializer.java
Outdated
Show resolved
Hide resolved
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/document/StrategyJsonSerializer.java
Outdated
Show resolved
Hide resolved
|
BTW can you take this out of draft? |
...ed/src/test/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocumentTest.java
Outdated
Show resolved
Hide resolved
We should have a test for this, doesn't look like we have one unless I missed it! |
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/document/DocumentJsonSerializer.java
Outdated
Show resolved
Hide resolved
.../java/software/amazon/awssdk/enhanced/dynamodb/internal/document/DocumentJsonSerializer.java
Outdated
Show resolved
Hide resolved
|
@dagnir do we need a changelog? its an internal implementation - so should be invisible? |
Good question; yes we should have an entry for this. It's a significant performance improvement that customers may be interested in. |
.changes/next-release/feature-AmazonDynamoDBEnhancedClient-798234c.json
Outdated
Show resolved
Hide resolved
0162e2d to
fd8a72b
Compare
|
|
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. |




This PR addresses a performance degradation issue between v1 and v2. After considering multiple implementation approaches, the proposed optimization approach yielded significant reduction in latency across the board.
toJson() Benchmarks
SDKJsonGenerator- writes tobyteArrayOutputStreamJsonGenerator- writes tostringWritergetJson() Benchmarks
50 bytes payload
100 bytes payload
500 bytes payload
1KB payload
High level Solution
Current Flow:
AttributeValue → JsonNode (via JsonItemAttributeConverter) → String (via JsonStringFormatHelper) → Stream joiningProposed Flow:
AttributeValue → SDKJsonGenerator → StringGeneral Optimization Approach
Instead of converting each
AttributeValueto aJsonNodeand then convertingJsonNodeto string via costly string builder and stream collection , we serializeAttributeValuesdirectly using SDKJsonGenerator methods which delegates all escaping and buffer management to Jackson core.SdkJsonGenerator (ByteArrayOutputStream) vs JsonGenerator (StringWriter)
Tested both serialization approaches with identical enum dispatch logic:
•
SdkJsonGeneratorwrapsJsonFactory.createGenerator(ByteArrayOutputStream)→ createsUTF8JsonGenerator- 19% faster (550µs vs 680µs at p90)•
JsonGeneratorwithJsonFactory.createGenerator(StringWriter)→ createsWriterBasedJsonGeneratorUTF8JsonGeneratorescapes non ASCII as \uXXXX by default. Jackson 2.18+ providesCOMBINE_UNICODE_SURROGATES_IN_UTF8feature to output literal UTF-8 (verified via test), but the SDK bundles older shaded Jackson version that lacks this feature.see FasterXML/jackson-core#223
UPDATE this should be mitigated with Jackson 2.19.4 that is now merged.