[
https://issues.apache.org/jira/browse/ARROW-1712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16329357#comment-16329357
]
ASF GitHub Bot commented on ARROW-1712:
---------------------------------------
wesm commented on a change in pull request #1481: ARROW-1712: [C++] Add method
to BinaryBuilder to reserve space for value data
URL: https://github.com/apache/arrow/pull/1481#discussion_r162163169
##########
File path: cpp/src/arrow/builder.cc
##########
@@ -1222,9 +1222,14 @@ Status BinaryBuilder::Init(int64_t elements) {
Status BinaryBuilder::Resize(int64_t capacity) {
DCHECK_LT(capacity, std::numeric_limits<int32_t>::max());
// one more then requested for offsets
- RETURN_NOT_OK(offsets_builder_.Resize((capacity + 1) * sizeof(int64_t)));
+ RETURN_NOT_OK(offsets_builder_.Resize((capacity + 1) * sizeof(int32_t)));
return ArrayBuilder::Resize(capacity);
}
+
+Status BinaryBuilder::ReserveData(int64_t capacity) {
+ DCHECK_LT(capacity, std::numeric_limits<int32_t>::max());
+ return value_data_builder_.Resize(capacity * sizeof(int64_t));
Review comment:
I think this should be `Resize(capacity + value_data_builder_.length())`.
The `sizeof(int64_t)` looks like a copy-paste error from implementation of
`BinaryBuilder::Resize` above (and that should be `sizeof(int32_t)` there, so
we should fix that)
We should check that `extra_capacity + length` does not exceed INT32_MAX but
probably return `Status::Invalid` since overflowing a `BinaryBuilder` is likely
to happen somewhat more regularly
I note also that `BufferBuilder` and `TypedBufferBuilder<T>` don't have a
`shrink_to_fit` option in their `Resize` method, that would be good to add to
avoid unnecessary reallocations
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [C++] Add method to BinaryBuilder to reserve space for value data
> -----------------------------------------------------------------
>
> Key: ARROW-1712
> URL: https://issues.apache.org/jira/browse/ARROW-1712
> Project: Apache Arrow
> Issue Type: Improvement
> Components: C++
> Reporter: Wes McKinney
> Assignee: Panchen Xue
> Priority: Major
> Labels: pull-request-available
> Fix For: 0.9.0
>
>
> The {{Resize}} and {{Reserve}} methods only reserve space for the value
> offsets. When building binary/string arrays with a known size (or some
> reasonable estimate), it would be more efficient to reserve once at the
> beginning to prevent internal reallocations
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)