Skip to content

Add internal API for fast module access from heap type methods #101476

@erlend-aasland

Description

@erlend-aasland

See topic on Discourse.

For CPython internal usage, we've got _PyModule_GetState, which is a fast variant of PyModule_GetState, the module check in the latter is simply an assert in the former.

For PyType_GetModuleState, there are three ifs (two of them implicitly in PyType_GetModule):

  1. check that the given type is a heap type
  2. check that the given type has an associated module
  3. check that the result of PyType_GetModule is not NULL

For stdlib core extension modules, all of these conditions are always true (AFAIK). With a fast static inlined variant, for example _PyType_GetModuleState, with a fast variant of PyType_GetModule inlined, where all three conditions are assert()ed, we can speed up a heap type methods that need to access module state.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions