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
Pickling objects by name without __module__ is suboptimal #122459
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.
Activity
pythongh-122459: Optimize pickling by name objects without __module__
serhiy-storchaka commentedon Aug 3, 2024
I did not expect significant effect from this change, but it make pickling a function without
__module__with the Python implementation twice faster:This affects also pickling
EllipsisandNotImplementedsingletons:The main purpose is of course cleaning up the code.
gh-122459: Optimize pickling by name objects without __module__ (GH-1…
pythongh-122459: Optimize pickling by name objects without __module__ (…
pythongh-122459: Optimize pickling by name objects without __module__ (…