-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
In PR #16506, we added #[recursive]
annotations (behind the recursive_protection
feature flag) to a subset of recursive functions across the optimizer, physical planner, and expression evaluator. While this prevented stack-overflow panics on deeply nested plans, benchmarks showed a 1–2% slowdown in planning time when the feature is enabled.
“The benchmarks seem to imply this has some non trivial overhead (slows down planning by 1–2%).
I wonder if there is any way to restructure the affected codepaths to avoid the recursion (change them into an iterative version, for example, or Box more structures to reduce the stack size?)”
— @alamb
This epic will serve as a central place to explore multiple approaches (e.g., iterative rewrites, Box-based data structures to shrink stack usage, or other patterns) to reduce/eliminate deep recursion in key codepaths, remove the need for defensive macros, and regain any lost performance, all while still handling arbitrarily nested plans reliably.
To Reproduce
#16787 provides a reproducer.
Expected behavior
DataFusion doesn't overflow its stack.
Additional context
See the discussion in #16506