-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP: speed up Period creation #23500
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
Conversation
if p.freqstr != freqstr: | ||
msg = DIFFERENT_FREQ_INDEX.format(freqstr, p.freqstr) | ||
if p.freqstr != freq.freqstr: | ||
msg = DIFFERENT_FREQ_INDEX.format(freq.freqstr, p.freqstr) |
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.
everything here is orthogonal to the rest of the PR, right?
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.
Yeah, this is insignificant from a performance perspective - just related cleanup.
@@ -1567,12 +1567,12 @@ cdef class _Period(object): | |||
|
|||
@classmethod | |||
def _maybe_convert_freq(cls, object freq): | |||
if not is_offset_object(freq): |
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.
This looks fine, and the timings you posted look nice. Can you try adding the not is_offset_object
check at the top of tslibs.offsets.to_offset? Should get a similar performance improvement in a handful of other places.
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.
Sure, will give that a shot. Will be out for a bit so may be several hours before I can post the results.
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.
I'm not seeing any significant changes from implementing this - did you have a particular benchmark in mind?
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.
I didn’t have any one in mind, but had a hunch. Thanks for taking a look
so we should benchmark a list of Periods created with an offset and from a string. not sure if these are benchmarked now. |
@qwhelan can you merge master. pls retest the asv. does this show any significant speedups? |
Closing this as #24118 addresses the same issue more directly |
Pending discussion on #23475, these changes demonstrate a ~35x improvement in PeriodArray creation by pushing an
isinstance(freq, DateOffset)
check fromto_offset()
to_maybe_convert_freq()
.The one caveat on the benchmarks above is that they were run under Ubuntu on Windows 10, so may be substantially different than pure Linux (currently upgrading my desktop, so unavailable at the moment).
The root cause of the speedup here seems to be the elimination of 6 imports per Period object. Again, likely a Windows artifact but nevertheless seems to be an issue per cProfile:
git diff upstream/master -u -- "*.py" | flake8 --diff