Skip to content

PyType_GetModuleByDef is really slow. #119663

Open
@markshannon

Description

@markshannon

PyType_GetModuleByDef does a lot of work for what was a single memory read prior to sub-interpreters.

For example, #114682.

We should provide a more efficient way to get to the module state from the module def.

AFAICT, the function to get the module state is a pure function of the interpreter and the module def.
Since the module def already has a m_index field that is described as "The module's index into its interpreter's modules_by_index cache.", then a Py_GetModuleFromDef() function could be as simple as:

inline PyObject *
Py_GetModuleFromDef(PyModuleDef *def)
{
     return PyInterpreterState_Get()->modules_table[def->m_base.m_index];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions