Coder Social home page Coder Social logo

Comments (6)

robertwb avatar robertwb commented on May 17, 2024

@robertwb changed owner from robertwb to somebody
commented

from cython.

robertwb avatar robertwb commented on May 17, 2024

@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.

from cython.

robertwb avatar robertwb commented on May 17, 2024

@robertwb changed milestone to wishlist
commented

from cython.

robertwb avatar robertwb commented on May 17, 2024

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 __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.
commented

The same idea is reported in http://trac.cython.org/ticket/141. This should use cpdef semantics.

from cython.

robertwb avatar robertwb commented on May 17, 2024

scoder commented

The same applies to other special methods like __call__. (noted here to close http://trac.cython.org/ticket/141 as a duplicate)

from cython.

robertwb avatar robertwb commented on May 17, 2024

scoder commented

The test in tests/run/special_methods_T561.pyx has some test code for this:

6ae0222

from cython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.