Skip to content

Commit

Permalink
perf: Rolling 'iter_lookbehind' breeze through duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 22, 2024
1 parent e9a66e3 commit d7a3b13
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/polars-time/src/windows/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,21 @@ pub(crate) fn group_by_values_iter_lookbehind(
0
};
let mut end = start;
let mut last = time[start_offset];
Ok(time[start_offset..upper_bound]
.iter()
.enumerate()
.map(move |(mut i, t)| {
i += start_offset;

// Fast path for duplicates.
if *t == last && i > start_offset {
let len = end - start;
let offset = start as IdxSize;
return Ok((offset, len as IdxSize));
}
last = *t;

let lower = add(&offset, *t, tz.as_ref())?;
let upper = *t;

Expand Down

0 comments on commit d7a3b13

Please sign in to comment.