Serialization optimization for DDB enhanced Client#6507
Conversation
c0c396a to
6b2036a
Compare
|
BTW can you take this out of draft? |
We should have a test for this, doesn't look like we have one unless I missed it! |
|
@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. |
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.