-
Notifications
You must be signed in to change notification settings - Fork 132
Avoid some potential stack overflow cases with deep expression trees #6321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
| while exprs.len() > 1 { | ||
| let mut next_level = Vec::with_capacity(exprs.len().div_ceil(2)); | ||
| let mut chunks = exprs.chunks_exact(2); | ||
|
|
||
| for chunk in chunks.by_ref() { | ||
| // chunk is guaranteed to have exactly 2 elements | ||
| let left = chunk[0].clone(); | ||
| let right = chunk[1].clone(); | ||
| next_level.push(combine(left, right)); | ||
| } | ||
|
|
||
| // Handle the remainder (odd element) | ||
| if let Some(last) = chunks.remainder().first() { | ||
| next_level.push(last.clone()); | ||
| } | ||
|
|
||
| exprs = next_level; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do this better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classic review comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've personally found it inspiring
Merging this PR will not alter performance
Comparing Footnotes
|
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
Benchmarks: Random AccessSummary
|
Benchmarks: TPC-H SF=1 on NVMESummary
Detailed Results Table
|
Benchmarks: FineWeb NVMeSummary
Detailed Results Table
|
Benchmarks: TPC-H SF=1 on S3Summary
Detailed Results Table
|
Benchmarks: TPC-DS SF=1 on NVMESummary
Detailed Results Table
|
Benchmarks: TPC-H SF=10 on NVMESummary
Detailed Results Table
|
Benchmarks: FineWeb S3Summary
Detailed Results Table
|
Benchmarks: Statistical and Population GeneticsSummary
Detailed Results Table
|
Benchmarks: TPC-H SF=10 on S3Summary
Detailed Results Table
|
Benchmarks: Clickbench on NVMESummary
Detailed Results Table
|
Benchmarks: CompressionSummary
Detailed Results Table
|
| children: impl IntoIterator<Item = Expression>, | ||
| ) -> VortexResult<Self> { | ||
| let children: Arc<[Expression]> = children.into(); | ||
| let children = Vec::from_iter(children); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take a vec. otherwise a vec need to be collected here? or is there a opt around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried to keep the general shape of the API intact
joseph-isaacs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIcE
…6321) Closes #6296 1. Collect large `AND`/`OR` expressions into balanced trees instead of a left/right leaning tree, making any recursion into them shorter. 2. Drop `Expression` iteratively instead of the default recursive approach. 3. Following #6251, using encoding ids instead of deep `Array::display_tree` in logs and errors. --------- Signed-off-by: Adam Gutglick <adam@spiraldb.com>
Closes #6296
AND/ORexpressions into balanced trees instead of a left/right leaning tree, making any recursion into them shorter.Expressioniteratively instead of the default recursive approach.Array::display_treein logs and errors.