-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LazyLoader for delayed imports of slow modules #4653
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool.
An aside: could this also be applied to fix import-order issues (e.g. when something in cirq.devices
needs to import cirq.circuits
) that are currently handled by function-level imports?
I think so yes, I think I can probably craft a regex to look for those. |
This allows for delayed import for modules, which is useful when the modules load time is slow and we don't want these imports on a global level.
This allows for delayed import for modules, which is useful when the modules load time is slow and we don't want these imports on a global level.
A solution for #4648
This creates a class
LazyLoader
that can be used in place of an import and delays importing the module.For classes that take up extra initialization time this speeds the overall first import of cirq with the potential downside of slowing doing the first uses where it is used.
This PR applies this to previous cases of delayed imports in scipy.