zhuqi-lucas opened a new pull request, #21701: URL: https://github.com/apache/datafusion/pull/21701
## Which issue does this PR close? Closes #21700. ## Rationale for this change When an Extension node has no expressions, `map_expressions` was still cloning all inputs and calling `with_exprs_and_inputs` to reconstruct the node — wasted work since there are no expressions to transform. This is common for Extension nodes like view matching candidates that carry multiple children but no expressions. ## What changes are included in this PR? 1. **Code change** (`datafusion/expr/src/logical_plan/tree_node.rs`): Add early return when `node.expressions()` is empty, skipping the clone + rebuild path. 2. **Micro-benchmark** (`datafusion/expr/benches/map_expressions.rs`): Criterion benchmark comparing `map_expressions` on Extension nodes with and without expressions, varying the number of children (1, 3, 5, 10). ## Are these changes tested? Yes — existing tests pass, and the new benchmark validates the optimization. Benchmark results: | Children | no_expr (optimized) | with_expr (rebuild) | Speedup | |----------|--------------------|--------------------|---------| | 1 | 24 ns | 167 ns | 7x | | 3 | 23 ns | 192 ns | 8x | | 5 | 23 ns | 181 ns | 8x | | 10 | 24 ns | 216 ns | 9x | The `no_expr` path is constant time regardless of children count. In a real optimizer pipeline (~15 rules × 5-child Extension), this saves ~2.4 us per optimization pass. ## Are there any user-facing changes? No — purely internal optimization. No API changes. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
