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(rust, python): add optimizer passes and change initial order #8811

Merged
merged 2 commits into from May 12, 2023

Conversation

ritchie46
Copy link
Member

@ritchie46 ritchie46 commented May 12, 2023

The stack optimizer passes expression from root to leafs.

That means that this expression:

lit(1) * lit(2) + col("a")

would be exposed to the optimizer in this order:

  1. lit(1) * lit(2) + col("a")
  2. lit(1) * lit(2)
  3. lit(1)
  4. lit(2)
  5. col("a")

And that fused multiply add optimization already triggers on 1 before constant folding can be triggered on 2.

So this PR changes the initial traversal of the expressions so that the stack will first traversed in order 5, 4, .. 1, meaning that smaller argument optimizations can be triggered first.

This will increase the amount of passes we take, but hopefully the extra triggered optimizations will be worth it.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels May 12, 2023
{
let expr = unsafe { expr_arena.get_unchecked(current_expr_node) };
// don't apply rules to `col`, `lit` etc.
if expr.is_leaf() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This will be most expressions and it is pointless to optimize them as they are atomic.

@ritchie46 ritchie46 merged commit a784843 into main May 12, 2023
14 checks passed
@ritchie46 ritchie46 deleted the stack branch May 12, 2023 08:51
alexander-beedie pushed a commit to alexander-beedie/polars that referenced this pull request May 20, 2023
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
Development

Successfully merging this pull request may close these issues.

None yet

1 participant