GH-48977: [C++] Fix quadratic field name index construction on libc++ - #50970
Merged
Conversation
|
|
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes schema field-name index construction on libc++ to avoid quadratic behavior with duplicate names.
Changes:
- Uses reserved, hinted multimap insertion.
- Optimizes schema copying and
SchemaBuilder. - Adds distinct- and duplicate-name benchmarks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cpp/src/arrow/type.cc |
Optimizes name-index construction and schema copying. |
cpp/src/arrow/type_benchmark.cc |
Adds schema construction benchmarks. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
pitrou
reviewed
Aug 24, 2026
pitrou
approved these changes
Aug 25, 2026
Contributor
Author
|
@pitrou good to merge? I believe the 2 failures are unrelated known issues |
Member
|
You're right, those are unrelated. Thank you @advitrocks9 ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
Building a schema with 500,000 identically named fields takes about 300 seconds.
CreateNameToIndexMapfills anunordered_multimapwith one bareemplaceper field. libc++ keeps equal keys contiguous, so each unhinted insert walks to the end of the equal range before splicing, making the loop quadratic. libstdc++ splices next to the first match and is already linear.What changes are included in this PR?
emplace_hint(find(name), ...), the shape arvidjonasson worked out on the issue from the LLVM bug kou linked.reserve(fields.size())goes in alongside to pay for the extrafind.SchemaBuilder::Impl::AppendFieldhad the same pattern, andSchema's copy constructor now rebuilds fromfields_instead of copying the multimap node by node.Are these changes tested?
arrow-type-testpasses 157/157. Nothing observable changes, so no new unit test.type_benchmark.ccgains a schema construction case:duplicate_names/10000goes from 117 ms to 0.41 ms,distinct_namesis level to 7% faster.Are there any user-facing changes?
Fields sharing a name come back from
GetAllFieldsByNamein a different order. That order isn't a contract:GetAllFieldIndicessorts, both pyarrow callers reject more than one field, and the two standard libraries already disagree.arrow::schemaconstruction performance degrades to O(n^2) on libc++ for duplicate/unnamed fields #48977