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

Open
jbrockmendel opened this issue Aug 22, 2019 · 1 comment

Comments

@jbrockmendel
Copy link
Contributor

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
PyDateTime_IMPORT

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

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

cdef datetime make_dt3(obj):
    return datetime(obj.year, obj.month, obj.day, 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.

@scoder

This comment has been minimized.

Copy link
Contributor

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 Optimize.py (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
Projects
None yet
2 participants
You can’t perform that action at this time.