[Feature] Add "fast" AttributeValue factory methods to avoid Builder allocations and wire into DDB Enhanced Client#7107
Open
RanVaknin wants to merge 5 commits into
Conversation
…ircumvent builder pattern (#7039) * Add generated opt in fast construction factories for DDB AttributeValue to bypass builder allocations * Remove benchmark to use the existing Enhanced Client benchmark instead * Add FAST_UNSET to avoid repetitive codegen * Change scope of customization config from per service, to target specific shapes * Refactor collection type factories to use FAST_UNSET, codegen guard to apply only to MODEL shapes, and require copiers to generate * Remove customization to generate boilerplate codegen drift (without our changes) for ease of review * Add back customization flag to generate only codegen diff relevant to this PR * Add javadoc and more test coverage * Remove customization flag to showcase changes in subsequent commit * Re-enable flag for ease of review of codegen changes * Change factory method name from fastX() to createX() * Add validation logic
…e thew createX factory methods (#7073)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a codegen customization that generates per member static factory methods (createS, createN, createM, etc.) on union shapes, scoped exclusively to DynamoDB's AttributeValue, and wires those factories into the DDB Enhanced Client's WRITE path converters.
Wiring into the READ path (JSON unmarshalling) would require changes to the JSON protocol layer and is out of scope.
This feature branch consists of:
Context
AttributeValue construction and allocations is a substantial performance factor for the DDB client and consequently the DDB Enhanced client accounting for 1 to 15% overall CPU time (and on the HUGE payload size it accounted for 50% of overall Memory Allocations).
AttributeValue construction is a measurable cost on the DDB Enhanced Client write path. Each call to
AttributeValue.builder().s(value).build()performs a 3 allocations:1.
builder()allocates aBuilderImpland anEnumSetto track which union member is set2.
.s(value)assigns the value and runshandleUnionValueChange(EnumSet add + iterator)3.
.build()allocates the final immutable AttributeValue, copying fields from the builderThe createX factories eliminate steps 1 and 2 entirely.
Results:
Throughput (ops/s)
Allocations (B/op)
Implementaion
The codegen (
AwsServiceModel.java) now supports agenerateDirectUnionConstructorscustomization, a list of shape names for which to emit direct factories. When enabled for a shape, it generates:A shared constant for the null/unset case:
A private all-args constructor that assigns every field directly (no builder, no EnumSet):
A public static factory per union member , slightly different for scalars and for collection types (collections need a copy since they are mutable)
The flag is enabled for DynamoDB and DynamoDB Streams only (the sole union in both models is
AttributeValue).