You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PERF] Construction of known cdef classes can go through __new__ #1643
In driver, runtime and nvrtc, when an instance of a cdef class is contructed (usually as a return value), it just uses the obvious Python-level constructor, for example:
cdef CUtensorMap tensorMap = CUtensorMap()
This makes a slow Python-like call (the ironically named PyObject_FastCall).
Instead, following Cythons fast instantiation advice, we can use __new__, which will make a faster C-level call to __cinit__.
This worked for the first class I tried (CUtensorMap), because it has an empty __init__. For classes with things in __init__ we have to move that content to __cinit__ and hope that that doesn't cause subtle changes in behavior. Punting for now, since this doesn't seem as "low hanging" as I initially thought.
Activity
mdboom commentedon Feb 18, 2026
This worked for the first class I tried (
CUtensorMap), because it has an empty__init__. For classes with things in__init__we have to move that content to__cinit__and hope that that doesn't cause subtle changes in behavior. Punting for now, since this doesn't seem as "low hanging" as I initially thought.