js8544 commented on code in PR #14230:
URL: https://github.com/apache/arrow/pull/14230#discussion_r979338721
##########
cpp/src/gandiva/gdv_function_stubs.cc:
##########
@@ -129,8 +129,22 @@ int32_t gdv_fn_populate_varlen_vector(int64_t context_ptr,
int8_t* data_ptr,
auto buffer = reinterpret_cast<arrow::ResizableBuffer*>(data_ptr);
int32_t offset = static_cast<int32_t>(buffer->size());
- // This also sets the size in the buffer.
- auto status = buffer->Resize(offset + entry_len, false /*shrink*/);
+ auto new_size = offset + entry_len;
+ // preallocation, double the size to amortize costs
+ if (buffer->capacity() < new_size) {
+ auto status =
+ buffer->Reserve(std::max(buffer->capacity() * 2,
static_cast<int64_t>(new_size)));
+ if (!status.ok()) {
+ gandiva::ExecutionContext* context =
Review Comment:
done
##########
cpp/src/gandiva/tests/micro_benchmarks.cc:
##########
@@ -249,6 +250,31 @@ static void TimedTestAllocs(benchmark::State& state) {
schema, evaluator, data_generator, pool_, 1 * MILLION, 16 * THOUSAND,
state);
ASSERT_TRUE(status.ok());
}
+
+static void TimedTestOutputStringAllocs(benchmark::State& state) {
+ // schema for input fields
+ auto field_a = field("abcdefghijklmnopqrstuvwxyz", arrow::utf8());
+ auto schema = arrow::schema({field_a});
+ auto pool_ = arrow::default_memory_pool();
+ // output field
+ auto field_res = field("res", utf8());
+
+ // Build expression
+ auto node_a = TreeExprBuilder::MakeField(field_a);
+ auto upper = TreeExprBuilder::MakeFunction("upper", {node_a}, utf8());
+ auto length = TreeExprBuilder::MakeFunction("octet_length", {upper},
int32());
+ auto expr = TreeExprBuilder::MakeExpression(upper, field_res);
+
+ std::shared_ptr<Projector> projector;
+ ASSERT_OK(Projector::Make(schema, {expr}, TestConfiguration(), &projector));
+
+ FastUtf8DataGenerator data_generator(64);
+ ProjectEvaluator evaluator(projector);
+
+ Status status = TimedEvaluate<arrow::StringType, std::string>(
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]