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
Conversation
44cfad9
to
af4dec6
Compare
CodSpeed Performance ReportMerging #15819 will not alter performanceComparing Summary
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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); |
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.
diff / steps_n
is independent of the loop, it doesn't need recomputing each time
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.
Good observation 👍
slope
in interpolate
@@ -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); |
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 use iter
here. That should be faster.
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 |
The first
first
items have already been checked to be null, there's no need to match on them twiceAlso, the slope was being repeatedly recomputed for each element of the for-loop