bpo-32403: Faster date and datetime constructors#4993
Conversation
Modules/_datetimemodule.c
Outdated
There was a problem hiding this comment.
This is the part I'm not sure about. It feels weird to put special-case logic for a specific subclass in the base class logic, but it makes the methods that datetime inherits and doesn't re-implement itself (datetime.today and datetime.toordinal) considerably faster when I do this.
Another option might be to do a token implementation of all the date methods specifically calling the new_datetime_subclass_ex, or explicitly calling date.themethod and then using datetime.combine on the result.
Modules/_datetimemodule.c
Outdated
There was a problem hiding this comment.
Please try to follow the code style used in the rest of the file. We don't leave space between & and the variable or inside the parentheses.
Modules/_datetimemodule.c
Outdated
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
6c6115c to
92ac0c4
Compare
92ac0c4 to
b438cbe
Compare
|
@abalkin I believe I fixed the style issues. |
This fixes bpo-32403 and bpo-32404. The first one is a performance enhancement, the second is a bugfix.
Using this script to benchmark the alternate constructors, I see significant improvements in speed across the board (note that since the subclasses don't take the fast path, they are a reasonable proxy for the speed from before this patch). You can see the results on my laptop (using the debug build, not the profiling optimized build) below:
For comparision, here is the same script run against master:
https://bugs.python.org/issue32403