Repository navigation
perf(substrait): avoid quadratic field lookup when consuming ReadRel - #26190
ole-baranov wants to merge 2 commits into
Conversation
bvolpato
left a comment
There was a problem hiding this comment.
LGTM, thanks for the improvement. The fast path preserves the existing lookup fallback for missing and duplicate names. Substrait checks, Clippy, and the wide-read benchmark smoke run pass locally.
askalt
left a comment
There was a problem hiding this comment.
The patch looks good to me.
|
@ole-baranov Can you amend the description to follow .github/pull_request_template.md? |
Haven’t seen it. Thanks. |
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #26190 +/- ##
==========================================
- Coverage 82.80% 82.80% -0.01%
==========================================
Files 1149 1149
Lines 452205 452218 +13
Branches 452205 452218 +13
==========================================
+ Hits 374458 374464 +6
- Misses 54950 54953 +3
- Partials 22797 22801 +4
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@ole-baranov My tests do not show improved performance: |
d97794b to
9d075fc
Compare
I separated the commits to make testing more convenient. You can now run tests on these two commits separately. before the change: after the one: With |
Measure Substrait consumption of `SELECT c0` over a table with 100, 1000 and 10000 columns, to track the cost of ReadRel schema handling on wide tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ensure_schema_compatibility` and `apply_projection` looked up every field
of the Substrait base schema with a linear scan of the table schema, making
consumption of a read over a wide table O(m*n). Build a name->index map of
the table schema once instead. Missing or duplicated names fall back to the
existing DFSchema lookups, so errors and disambiguation are unchanged.
Consume time for `SELECT c0` over a table with N columns
(`consume_wide_read` benchmark):
columns before after
100 58 us 25.5 us
1000 2.33 ms 276 us
10000 211 ms 3.16 ms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9d075fc to
9fafbd3
Compare
|
hi @ole-baranov, I added required-feature protoc in #27153 because of adriangb/datafusion-benchmarking#49 Here are the runs: Both show slightly slower performance. |
hi @kosiew ! Could you share the commands you used to run the tests? |
Which issue does this PR close?
Rationale for this change
Substrait ReadRel consumption performed a linear scan over the table schema for every field, leading to O(m × n) lookups when scanning wide tables. This commit introduces a hash‑map lookup (unqualified_name_index) to map column names to indices once per schema, reducing the complexity to O(m + n). The change also adds a benchmark to expose the performance regression and confirm the improvement.
What changes are included in this PR?
What is the testing strategy for this PR?
cargo test --profile ci --workspace --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption.cargo bench --bench consume_wide_read.Are there any user‑facing changes?