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: skip initial null items and don't recompute slope in interpolate #15819

Merged
merged 4 commits into from Apr 22, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Apr 21, 2024

The first first items have already been checked to be null, there's no need to match on them twice

Also, the slope was being repeatedly recomputed for each element of the for-loop

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels Apr 21, 2024
Copy link

codspeed-hq bot commented Apr 21, 2024

CodSpeed Performance Report

Merging #15819 will not alter performance

Comparing MarcoGorelli:interpolate-skip-first (4fb4c58) with main (b4e43d7)

Summary

✅ 22 untouched benchmarks

@MarcoGorelli MarcoGorelli marked this pull request as ready for review April 21, 2024 13:04
Copy link

codecov bot commented Apr 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.37%. Comparing base (b4e43d7) to head (4fb4c58).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15819      +/-   ##
==========================================
- Coverage   80.38%   80.37%   -0.02%     
==========================================
  Files        1263     1263              
  Lines      165346   165346              
==========================================
- Hits       132918   132895      -23     
- Misses      32428    32451      +23     

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

Comment on lines -55 to +58
let diff = high - low;
let slope = (high - low) / steps_n;
for step_i in 1..steps {
let step_i: T = NumCast::from(step_i).unwrap();
let v = linear_itp(low, step_i, diff, steps_n);
let v = linear_itp(low, step_i, slope);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

diff / steps_n is independent of the loop, it doesn't need recomputing each time

Copy link
Member

Choose a reason for hiding this comment

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

Good observation 👍

@MarcoGorelli MarcoGorelli changed the title perf: skip initial null items in interpolate perf: skip initial null items and don't recompute slope in interpolate Apr 21, 2024
@@ -77,7 +77,7 @@ where

// Fill av with first.
let mut av = Vec::with_capacity(chunked_arr.len());
let mut iter = chunked_arr.into_iter();
let mut iter = chunked_arr.into_iter().skip(first);
Copy link
Member

Choose a reason for hiding this comment

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

Can we use iter here. That should be faster.

@ritchie46
Copy link
Member

This one is good to go. Thank yo @MarcoGorelli.

There is more performance to be gained here for a future PR, if someone is up for it.

Currently we iterator with ChunkedArray::iter, but it is still a nested iterator. If we unnest the loops it saves a branch on the inner loop.

@ritchie46 ritchie46 merged commit c8e5fdd into pola-rs:main Apr 22, 2024
21 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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants