Add Array::shrink_to_fit(&self) -> ArrayRef
#6787
Closed
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.
Which issue does this PR close?
shrink_to_fit
toArray
#6360Rationale for this change
Concatenating many arrow buffers incrementally can lead to situations where the buffers are using much more memory than they need (their capacity is larger than their lengths).
Example:
If you run this you will see 12 MB is used for 6 MB of data.
What changes are included in this PR?
This PR adds
shrink_to_fit
toArray
and all buffers.Are there any user-facing changes?
trait Array
now has afn shrink_to_fit(&self) -> ArrayRef
.Problems
I could not implement
Array::shrink_to_fit
forTypedDictionaryArray
norTypedRunArray
, since they are types wrapping references. Callingshrink_to_fit
on these will result in anunimplemented!
panic. Perhaps we should return an error instead.Due to the above problem, perhaps we should consider an alternative approach?