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

optiimization: substitute datetime_new for datetime where feasible #3089

jbrockmendel opened this issue Aug 22, 2019 · 1 comment


Copy link

commented Aug 22, 2019

If I do from cpython.datetime cimport datetime, the constructor dt = datetime(...) makes a python-space call that I think can be optimized:

from cpython.datetime cimport datetime, datetime_new, PyDateTime_IMPORT

cdef datetime make_dt1(obj):
     return datetime(obj.year, obj.month,, obj.hour, obj.minute, obj.second,, obj.tzinfo)

cdef datetime make_dt2(obj):
     return datetime_new(obj.year, obj.month,, obj.hour, obj.minute, obj.second,, obj.tzinfo)

cdef datetime make_dt3(obj):
    return datetime(obj.year, obj.month,, tzinfo=obj.tzinfo)

It should be straightforward to make the substitution in the case of make_dt1 where all args are passed as positional. The make_dt3 usage is hairier.


This comment has been minimized.

Copy link

commented Aug 23, 2019

Might not be entirely trivial, since this is referring to a non-builtin and I don't think we're doing anything in that regard already. But it could probably be integrated with the builtin specialisations in (there is a dispatch mechanism to handler methods by name). PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.