Skip to content

Commit

Permalink
perf: Speed up list operations that use amortized_iter() (#20964)
Browse files Browse the repository at this point in the history
Co-authored-by: Itamar Turner-Trauring <[email protected]>
  • Loading branch information
itamarst and pythonspeed authored Feb 7, 2025
1 parent 6953b9d commit 631d41f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/polars-core/src/chunked_array/list/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::marker::PhantomData;
use std::ptr::NonNull;
use std::rc::Rc;

use crate::chunked_array::flags::StatisticsFlags;
use crate::prelude::*;
use crate::series::amortized_iter::{unstable_series_container_and_ptr, AmortSeries, ArrayBox};

Expand Down Expand Up @@ -81,10 +82,13 @@ impl<I: Iterator<Item = Option<ArrayBox>>> Iterator for AmortizedListIter<'_, I>
// update the inner state
unsafe { *self.inner.as_mut() = array_ref };

// As an optimization, we try to minimize how many calls to
// _get_inner_mut() we do.
let series_mut_inner = series_mut._get_inner_mut();
// last iteration could have set the sorted flag (e.g. in compute_len)
series_mut.clear_flags();
series_mut_inner._set_flags(StatisticsFlags::empty());
// make sure that the length is correct
series_mut._get_inner_mut().compute_len();
series_mut_inner.compute_len();
}

// SAFETY:
Expand Down

0 comments on commit 631d41f

Please sign in to comment.