Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cpp/src/arrow/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,11 @@ namespace {
std::unordered_multimap<std::string_view, int> CreateNameToIndexMap(
const FieldVector& fields) {
std::unordered_multimap<std::string_view, int> name_to_index;
name_to_index.reserve(fields.size());
for (size_t i = 0; i < fields.size(); ++i) {
name_to_index.emplace(fields[i]->name(), static_cast<int>(i));
const std::string_view name = fields[i]->name();
// The find() hint avoids libc++'s quadratic scan of equal keys on plain emplace.
name_to_index.emplace_hint(name_to_index.find(name), name, static_cast<int>(i));
Comment thread
pitrou marked this conversation as resolved.
}
return name_to_index;
}
Expand Down Expand Up @@ -2294,7 +2297,7 @@ Schema::Schema(FieldVector fields, std::shared_ptr<const KeyValueMetadata> metad
impl_(new Impl(std::move(fields), Endianness::Native, std::move(metadata))) {}

Schema::Schema(const Schema& schema)
: detail::Fingerprintable(), impl_(new Impl(*schema.impl_)) {}
: Schema(schema.impl_->fields_, schema.impl_->endianness_, schema.impl_->metadata_) {}
Comment thread
advitrocks9 marked this conversation as resolved.

Schema::~Schema() = default;

Expand Down Expand Up @@ -2568,7 +2571,9 @@ class SchemaBuilder::Impl {
}

Status AppendField(const std::shared_ptr<Field>& field) {
name_to_index_.emplace(field->name(), static_cast<int>(fields_.size()));
const std::string_view name = field->name();
name_to_index_.emplace_hint(name_to_index_.find(name), name,
static_cast<int>(fields_.size()));
fields_.push_back(field);
return Status::OK();
}
Expand Down
22 changes: 22 additions & 0 deletions cpp/src/arrow/type_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ static void SchemaEqualsWithMetadata(
state.SetItemsProcessed(state.iterations() * 2);
}

static void SchemaConstruct(benchmark::State& state, // NOLINT non-const reference
bool duplicate_names) {
const int num_fields = static_cast<int>(state.range(0));
FieldVector fields(num_fields);
for (int i = 0; i < num_fields; ++i) {
fields[i] = field(duplicate_names ? "f" : "f" + std::to_string(i), int32());
}

for (auto _ : state) {
benchmark::DoNotOptimize(::arrow::schema(fields));
}
state.SetItemsProcessed(state.iterations() * num_fields);
}

// ------------------------------------------------------------------------
// Micro-benchmark various error reporting schemes

Expand Down Expand Up @@ -541,6 +555,14 @@ BENCHMARK(TypeEqualsComplex);
BENCHMARK(TypeEqualsWithMetadata);
BENCHMARK(SchemaEquals);
BENCHMARK(SchemaEqualsWithMetadata);
BENCHMARK_CAPTURE(SchemaConstruct, distinct_names, /*duplicate_names=*/false)
->Arg(100)
->Arg(1000)
->Arg(10000);
BENCHMARK_CAPTURE(SchemaConstruct, duplicate_names, /*duplicate_names=*/true)
->Arg(100)
->Arg(1000)
->Arg(10000);

BENCHMARK(ErrorSchemeNoError);
BENCHMARK(ErrorSchemeBool);
Expand Down
Loading