Skip to content
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

Merged
merged 4 commits into from
May 31, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented May 31, 2024

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:

  • main: 0.07145315833349741
  • here: 0.017829982333144773

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels May 31, 2024
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);
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

: )

@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 31, 2024 08:40
@MarcoGorelli MarcoGorelli marked this pull request as draft May 31, 2024 08:41
Copy link

codecov bot commented May 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.51%. Comparing base (d7b4f72) to head (4d7edd4).
Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@MarcoGorelli MarcoGorelli marked this pull request as ready for review May 31, 2024 09:26
@ritchie46 ritchie46 merged commit b85c5e0 into pola-rs:main May 31, 2024
21 checks passed
@cmdlineluser cmdlineluser mentioned this pull request Jun 7, 2024
2 tasks
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dt.truncate is 3-4x slower in polars compared to pandas
2 participants