Skip to content
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

perf: Remove cast to boolean after comparison in optimizer #21022

Merged

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Jan 31, 2025

Drive-by renames fn coerce_types() to fn optimize_exprs() under ConversionOptimizer, as it also does other optimizations aside from type coercion.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels Jan 31, 2025
@nameexhaustion nameexhaustion changed the title perf: Remove boolean cast after comparison in optimizer perf: Remove cast to boolean after comparison in optimizer Jan 31, 2025
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 93.47826% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.14%. Comparing base (ea1ea5a) to head (7305d1a).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...ars-plan/src/plans/conversion/type_coercion/mod.rs 93.33% 2 Missing ⚠️
...ates/polars-plan/src/plans/conversion/stack_opt.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21022      +/-   ##
==========================================
- Coverage   79.20%   79.14%   -0.07%     
==========================================
  Files        1583     1583              
  Lines      225109   225126      +17     
  Branches     2581     2581              
==========================================
- Hits       178303   178179     -124     
- Misses      46216    46357     +141     
  Partials      590      590              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if let Some(schema) = lp_arena.get(lp_node).input_schema(lp_arena) {
let field = aexpr.to_field(&schema, Context::Default, expr_arena)?;
if field.dtype == *dtype {
return Ok(Some(aexpr.clone()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why this not returns None? I understand it returns the same aexpr untouched.

Copy link
Collaborator Author

@nameexhaustion nameexhaustion Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aexpr in this function is the input expr to the cast (not the cast itself), you can see how it is called if you expand the diff above -
Screenshot_20250201_002429_Chrome

So by returning it here we replace the cast expr with its input, which removes the cast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I see. Thanks!

@ritchie46 ritchie46 merged commit 3c497e3 into pola-rs:main Jan 31, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
None yet
2 participants