Skip to content

chores and performance boost#9

Merged
AdilZouitine merged 2 commits intoonline-ml:masterfrom
OctopusTakopi:master
Jul 12, 2025
Merged

chores and performance boost#9
AdilZouitine merged 2 commits intoonline-ml:masterfrom
OctopusTakopi:master

Conversation

@OctopusTakopi
Copy link
Contributor

chores:

  • update crates
  • fix typos
  • make clippy happy
  • update info link

perf:

  • Static Dispatch: By making Rolling<'a, U, F> generic over U: RollableUnivariate, method calls (update, revert, get) use static dispatch (monomorphized code) instead of dynamic (vtable)
  • Same Static Dispatch technique for iter.

* update crates

* fix typos

* make clippy happy

* update info link

perf:

* Static Dispatch: By making Rolling<'a, U, F> generic over U: RollableUnivariate<F>, method calls (update, revert, get) use static dispatch (monomorphized code) instead of dynamic (vtable)

* same Static Dispatch techinic for iter.
@AdilZouitine AdilZouitine requested a review from Copilot July 11, 2025 12:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR performs general maintenance (dependency bumps, typo fixes, Clippy cleanups) and applies a performance optimization by replacing dynamic dispatch with static dispatch in two core abstractions.

  • Updated Rolling to be generic over the concrete RollableUnivariate type, preallocating its window buffer.
  • Refactored IterStat to use generic stat types instead of boxed trait objects.
  • Bumped num and ordered-float versions, fixed doc typos, and replaced a manual match with the ? operator.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/rolling.rs Made Rolling generic over U for static dispatch, preallocate VecDeque, adjusted error type
src/quantile.rs Corrected reference titles and updated URLs in documentation
src/mean.rs Simplified revert by using the ? operator instead of manual match
src/iter.rs Changed IterStat to accept a generic stat type (U) instead of Box<dyn Univariate>
Cargo.toml Bumped dependency versions for num and ordered-float

U: RollableUnivariate<F>,
F: Float + FromPrimitive + AddAssign + SubAssign,
{
fn update(&mut self, x: F) {
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The update method never forwards the new value to to_roll.update(x) or pushes x onto window, so the sliding-window logic is broken; you should call self.to_roll.update(x) and self.window.push_back(x) after handling the oldest element.

Copilot uses AI. Check for mistakes.
src/rolling.rs Outdated
{
pub fn new(to_roll: &'a mut U, window_size: usize) -> Result<Self, &'static str> { // Optimization: &'static str for error (clearer, no lifetime tie)
if window_size == 0 {
return Err("Window size should not equals to 0");
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

[nitpick] Grammar: change the error message to something like "Window size must be non-zero" or "Window size should not equal 0".

Suggested change
return Err("Window size should not equals to 0");
return Err("Window size must be non-zero");

Copilot uses AI. Check for mistakes.
src/rolling.rs Outdated
/// let mut running_sum: Sum<f64> = Sum::new();
/// // We wrap `running_sum` inside the `Rolling` struct.
/// let mut rolling_sum: Rolling<f64> = Rolling::new(& mut running_sum, 2).unwrap();
/// let mut rolling_sum: Rolling<_, f64> = Rolling::new(& mut running_sum, 2).unwrap();
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

[nitpick] Style: remove the extra space in & mut; it should be &mut running_sum to match Rust idioms.

Suggested change
/// let mut rolling_sum: Rolling<_, f64> = Rolling::new(& mut running_sum, 2).unwrap();
/// let mut rolling_sum: Rolling<_, f64> = Rolling::new(&mut running_sum, 2).unwrap();

Copilot uses AI. Check for mistakes.
@AdilZouitine
Copy link
Member

Great contribution, I will take a look on the code to review it asap 😄
@raphaelsty, if you want to take a look too

@AdilZouitine AdilZouitine requested a review from raphaelsty July 11, 2025 13:00
@raphaelsty
Copy link
Member

raphaelsty commented Jul 11, 2025

Great MR, I'll review it asap, so far LGTM as test pass @OctopusTakopi @AdilZouitine

@OctopusTakopi
Copy link
Contributor Author

image

pdf
pdf

Simple rolling sum bench: ~18% less compute time on my machine with 100000 data points and 100 window size

Copy link
Member

@AdilZouitine AdilZouitine left a comment

Choose a reason for hiding this comment

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

LGTM, flawless thank you 😄

@AdilZouitine AdilZouitine merged commit d206eb5 into online-ml:master Jul 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants