-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: make truncate 4x faster in simple cases #16615
Conversation
crates/polars-time/src/truncate.rs
Outdated
let offset: Duration = Duration::parse(offset); | ||
let time_zone = self.time_zone(); | ||
// A sqrt(n) cache is not too small, not too large. | ||
let mut duration_cache = FastFixedCache::new((every.len() as f64).sqrt() as usize); |
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 allocate the cache below the fast path. The fast path only accesses the cache (and misses) once.
&& (every.months() == 0 && every.weeks() == 0) | ||
{ | ||
// ... yes we can! Weeks, months, and time zones require extra logic. | ||
// But in this simple case, it's just simple integer arithmetic. |
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.
: )
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16615 +/- ##
==========================================
- Coverage 81.51% 81.51% -0.01%
==========================================
Files 1414 1414
Lines 185906 185940 +34
Branches 3027 3027
==========================================
+ Hits 151535 151561 +26
- Misses 33840 33848 +8
Partials 531 531 ☔ View full report in Codecov by Sentry. |
closes #16531
This introduces a fastpath for the simplest case
I think the non-simple case can also be optimised, but that's a separate task. I've made a tracker: #16617. I'll work on it
timings on the OPs issue: