Expose ByteBuffer
values by const reference from DynamoDB::Model::AttributeValue
#3031
Labels
ByteBuffer
values by const reference from DynamoDB::Model::AttributeValue
#3031
Describe the feature
When fetching from DynamoDB and accessing a binary data field,
AttributeValue::GetB()
makes a copy of the underlyingByteBuffer
(that's held in a shared pointer to hopefully an appropriateAttributeValueValue
instance).This indeed allows returning an empty buffer if the type is not actually
ValueType::BYTEBUFFER
, but in the happy path, also probably the very common case, this means we're making a copy of all fetched data. It seems like we could support the same API without such copy.Use Case
Avoiding the pointless copy should benefit performance (mostly better utilization of memory cache) and reduce memory requirements.
Proposed Solution
If the type is indeed
ValueType::BYTEBUFFER
, return a const reference to the underlyingByteBuffer
, otherwise return a const reference to a static emptyByteBuffer
, which could be e.g. a static member ofAttributeValueValue
.An even better solution would be to allow moving the underlying data, something like
Aws::Utils::ByteBuffer GetBWithOwnership()
where, in case of a type mismatch, the implementation could simply instantiate an empty buffer.
Other Information
The same holds true for the other DynamoDB value types. Since the API returns a default when the type is not as expected, it may as well return a const reference to the actual data in the happy path, otherwise a const reference to a static default of the appropriate type. Or, even better, allow moving all types of values.
Acknowledgements
The text was updated successfully, but these errors were encountered: