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
Cython calls ExtType.__init__() as Python function #560
Comments
@robertwb changed owner from |
@garyfurnish commented One of the first things I do is make my own c wrappers for creating objects. Even with the expensive new call the savings it noticeable. |
@robertwb changed milestone to |
scoder changed description from When subclasses of extension types call the init() method of their supertype, Cython generates code that looks up the "init" attribute of the instance and then calls it through Python using arg tuple/kwargs. This is because the special init() method ("tp_init" slot) uses this call signature. Cython should recognise calls to this method and at least call it directly. In the (presumably very common) case that the arguments do not use starargs, a more advanced approach would be to split the init() method into an internal plain C-function replacement and a tp_init wrapper, and then call the internal function directly, without doing any tuple packing etc. Not sure if it's worth it, though, as the call is already preceded by an (expensive) object allocation. to When subclasses of extension types call the Cython should recognise calls to this method and at least call it directly. In the (presumably very common) case that the arguments do not use starargs, a more advanced approach would be to split the The same idea is reported in http://trac.cython.org/ticket/141. This should use cpdef semantics. |
scoder commented The same applies to other special methods like |
scoder commented The test in tests/run/special_methods_T561.pyx has some test code for this: |
When subclasses of extension types call the
__init__()
method of their supertype, Cython generates code that looks up the "__init__
" attribute of the instance and then calls it through Python using arg tuple/kwargs. This is because the special__init__()
method ("tp_init
" slot) uses this call signature.Cython should recognise calls to this method and at least call it directly.
In the (presumably very common) case that the arguments do not use starargs, a more advanced approach would be to split the
__init__()
method into an internal plain C-function replacement and atp_init
wrapper, and then call the internal function directly, without doing any tuple packing etc. Not sure if it's worth it, though, as the call is already preceded by an (expensive) object allocation.Migrated from http://trac.cython.org/ticket/3
The text was updated successfully, but these errors were encountered: