Skip to content

Commit

Permalink
perf: Keep more parallelism when CSE plan cache hits (pola-rs#17463)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored and Henry Harbeck committed Jul 8, 2024
1 parent 7cb1683 commit 4b23ccd
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions crates/polars-plan/src/plans/optimizer/cache_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,37 @@ pub(super) fn set_cache_states(
match lp {
// don't allow parallelism as caches need each others work
// also self-referencing plans can deadlock on the files they lock
Join { options, .. } if options.allow_parallel => {
if let Join { options, .. } = lp_arena.get_mut(frame.current) {
let options = Arc::make_mut(options);
options.allow_parallel = false;
Join {
options,
input_left,
input_right,
..
} if options.allow_parallel => {
let has_cache_in_children = [*input_left, *input_right].iter().any(|node| {
(&*lp_arena)
.iter(*node)
.any(|(_, ir)| matches!(ir, IR::Cache { .. }))
});
if has_cache_in_children {
if let Join { options, .. } = lp_arena.get_mut(frame.current) {
let options = Arc::make_mut(options);
options.allow_parallel = false;
}
}
},
// don't allow parallelism as caches need each others work
// also self-referencing plans can deadlock on the files they lock
Union { options, .. } if options.parallel => {
if let Union { options, .. } = lp_arena.get_mut(frame.current) {
options.parallel = false;
Union { options, inputs } if options.parallel => {
// Only toggle if children have a cache, otherwise we loose potential parallelism for nothing.
let has_cache_in_children = inputs.iter().any(|node| {
(&*lp_arena)
.iter(*node)
.any(|(_, ir)| matches!(ir, IR::Cache { .. }))
});
if has_cache_in_children {
if let Union { options, .. } = lp_arena.get_mut(frame.current) {
options.parallel = false;
}
}
},
Cache { input, id, .. } => {
Expand Down

0 comments on commit 4b23ccd

Please sign in to comment.