advitrocks9 commented on code in PR #50970:
URL: https://github.com/apache/arrow/pull/50970#discussion_r3849636367
##########
cpp/src/arrow/type.cc:
##########
@@ -1333,8 +1333,10 @@ 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();
+ name_to_index.emplace_hint(name_to_index.find(name), name,
static_cast<int>(i));
Review Comment:
Done in 4cacc16.
##########
cpp/src/arrow/type.cc:
##########
@@ -2294,7 +2296,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_) {}
Review Comment:
Copying the Impl copies the multimap, and libc++'s multimap copy constructor
re-inserts each element without a hint, so it has the same quadratic problem.
See
https://github.com/llvm/llvm-project/blob/release/21.x/libcxx/include/unordered_map#L2319-L2324.
Rebuilding through CreateNameToIndexMap uses the hinted path.
--
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]