Skip to content

Pickling objects by name without __module__ is suboptimal #122459

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

When the object is pickled by name (classes, functions, and other enum-like objects) has no __module__ attribute or it is None, the code searches the object in all imported modules: tries to resolve its name relatively to the module and check that the result is the same object.

Whether the module was get from the __module__ attribute or found in sys.modules, the code checks it again:
Then it checks again: tries to resolve its name relatively to the module and check that the result is the same object.

So in some the work is repeated twice. The following PR makes it only be performed once. It also contains few other minor optimizations and simplifications.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesperformancePerformance or resource usage

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions