-
-
Notifications
You must be signed in to change notification settings - Fork 81
perf: Improve import time by lazy import "slow" modules #1037
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1037 +/- ##
==========================================
- Coverage 87.46% 87.46% -0.01%
==========================================
Files 9 9
Lines 4948 4955 +7
==========================================
+ Hits 4328 4334 +6
- Misses 620 621 +1 ☔ View full report in Codecov by Sentry. |
param/parameterized.py
Outdated
| # Only update signature in an IPython environment | ||
| if not hasattr(builtins, "__IPYTHON__"): | ||
| return |
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.
This was added to #742, and as far as I can see, it was done to improve the experience in IPython.
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.
Maybe also the doc experience, though I'm unsure if this comes from types or the signature.
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.
Wasn't there a regression in Panel recently because of hasattr(builtins, "__IPYTHON__")?
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.
Yes, in holoviz/panel#7734. I pushed the change before that PR.
We could likely change it to hasattr(builtins, "__IPYTHON__") or hasattr(builtins, "get_ipython"), and make it a constant so it does not need to look up all the time.
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.
For my own understanding, why was the code changed in Panel and other places from try: get_ipython()/except to hasattr(builtins, "__IPYTHON__")?
We could likely change it to
hasattr(builtins, "__IPYTHON__") or hasattr(builtins, "get_ipython"), and make it a constant so it does not need to look up all the time.
Wasn't the regression in Panel that hasattr(builtins, "__IPYTHON__") was True but get_python was not available? I'd like to understand when that can happen.
Btw Param has a _in_ipython utility function.
0c477cd to
f26a2d6
Compare
|
What's the Python version used for all these benchmarks? Deferring the import of modules from the stdlib is a bit sad but well. I recommend opening 2 PRs, one for the deferred stdlib imports, one for the signature. |
Honestly, I would rather not. I don't think there is any discussion about deferring imports, only around the signature, and both are related to import time. |
Sorry I wasn't clear enough. It was not about discussing the changes, but about separating them. The deferred imports are an implementation detail imo, while the updated signature is a breaking change. |
Hopefully not? If it was always meant to only work in IPython it should not be a breaking change. |
f26a2d6 to
3d4885b
Compare
|
Split into two PRs see #1038. The result in the main post still contains the combined effort of these two prs. |
This PR improves the import time by postponing the import of
asyncio,logging, andhtml. And also not updating signatures if not inside a IPython environment.Import time + tuna
Generated with
python -X importtime -c 'import param' 2> tuna.log && tuna tuna.log. Some notes only focus on the param and ignore theparam.versiontime; also, the measurement is not exact (see hyperfine) and needs warmup time after a branch change.Main (9ff6a9f):

After removing asyncio (5a63a9e):

+After removing logging and HTML (3d4885b)+Without updating signature in__init_submodules__(30180b8):Pyinstrument
Also used pyinstrument with
pyinstrument -r html example.pywhere example.py isimport paramMain (9ff6a9f)

This PR (30180b8):

hyperfine
Main (9ff6a9f)
This PR (30180b8):