spanner: decoder should re-use arg arrays #749
Labels
api: spanner
Issues related to the Spanner API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Currently, when the spanner client decodes an array column, it always creates a new array. This can result in more memory allocation than necessary. In this example, memory for
a
is reallocated for each row.This behavior is certainly safer than re-using memory, when the caller saves
a
for later use. But it makes it impossible to control memory. If we instead re-used the memory ofa
, then users could choose whether they wanted to save memory or make a copy.If we do this, I recommend the following algorithm, which is consistent with the BigQuery client: if the given slice is too short (which includes the case where it is nil), allocate a new one. Otherwise, slice the given one to the right length and reuse it.
/cc @pongad @vkedia
The text was updated successfully, but these errors were encountered: