Skip to content

[PERF] Construction of known cdef classes can go through __new__ #1643

Open

Description

@mdboom

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

cdef CUtensorMap tensorMap = CUtensorMap.__new__(CUtensorMap)

Activity

  1. self-assigned this
    on Feb 18, 2026
  2. mdboom commented on Feb 18, 2026

    @mdboom
    ContributorAuthor

    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.

  3. removed their assignment
    on Feb 19, 2026
  4. added this to the cuda.core v0.7.0 milestone on Feb 27, 2026
  5. removed this from the cuda.bindings backlog milestone on Apr 2, 2026
  6. removed their assignment
    on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Low priority - Nice to havecuda.bindingsEverything related to the cuda.bindings moduleperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions