Closed hagenw closed 9 months ago
I looked into it and the extra time is completely covered by importlib_metadata.packages_distributions()
which we call inside audobject.core.utils.create_class_key()
:
It's unfortunate as we only have a different package name in very rare cases. So it would be better to call it only if really needed, but so far I don't see how to achieve this.
Maybe we can first try with module_name
and only if we cannot create the object call packages_distributions()
?
The package_name
is indeed only needed if autoinstall=True
, see
But the problem is we can only call packages_distributions()
when the package is already installed, so indeed at the time we are storing the object and not when loading it as the mapping from module_name
to package_name
is ambiguous.
packages_distributions()
is also collecting the information for all installed packages and not only for the package we require. Maybe we can look into the source code of packages_distributions()
, provide the module name as argument and use only the code we need.
The code inside importlib_metadata.packages_distributions()
does indeed loop over all packages, which might not be needed, compare https://github.com/python/importlib_metadata/blob/353c3dfe83e08b3c86f30d192c315501cef97454/importlib_metadata/__init__.py#L955-L969
Serializing an object to YAML and loading it from there adds a big overhead (factor 100), which seems not reasonable to me:
Then we get: