-
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
Delay import of scipy stats and optimize #4643
Conversation
Before the PR gives 1.7412576620699838 and after gives 1.355757946963422 |
Current slowness besides these scipy modules are |
This looks good. Did you have the time to checkout something like this: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py#L23 at all ? Which would give us the added bonus of being able to start rounding up all the random imports we have littered everywhere to avoid circular imports (putting them back at the top with this) ? |
Untested TensorFlow code! My eyes they burn! The googles they do nothing! Do you see the benefit of the TensorFlow class? I guess if you use the class in a lot of places? |
Well you don't have to worry about where in the module you'd need to put your imports if you used this class. The actual load would take place when the call is made. So in this case of scipy instead of having to put multiple imports in weid places just do at the top: # can do circular imports at the top with this too.
scipy_linalg = LazyLoader("scipy.whatever", globals())
def my_function(...):
stuff.
def my_scipy_function(...):
return scipy_linalg.whatever # this triggers actual import. |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Created #4648 to consider adding LazyLoader. |
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.
LGTM, we should probably hold off on more like this for now until a decision is made on the LazyLoader approach (otherwise we might just be making more work for ourselves here).
This speeds up top level import. Note that we had previously done this for another use of scipy.stats, but this one got added. Also doing it for scipy.optimize. Both of these can slow down the resulting experiments, probably a case for moving experiments out of cirq-core?
This speeds up top level import. Note that we had previously done this for another use of scipy.stats, but this one got added. Also doing it for scipy.optimize. Both of these can slow down the resulting experiments, probably a case for moving experiments out of cirq-core?
This speeds up top level import.
Note that we had previously done this for another use of scipy.stats, but this one got added. Also doing it for scipy.optimize. Both of these can slow down the resulting experiments, probably a case for moving experiments out of cirq-core?