Improve import time
Importing dantro takes quite some time currently ... on my machine it's about 2.5s. It would be nice if we could bring this down a bit, e.g. by delaying package imports until the point that they are needed, and by perhaps dropping a few superfluous imports.
I profiled this from utopya
using python -X importtime -c 'import utopya' 2> ../utopya-import-times.txt
and got this result. The cumulative import times are especially high for the following imports:
package | cumulative time [ms] | comment |
---|---|---|
utopya |
2600 | (for orientation) |
dantro |
2500 | (for orientation) |
dantro.plot_creators |
770 | self-time is ok, most of it comes from seaborn
|
seaborn |
520 | easy to delay |
matplotlib.pyplot |
180 | not super bad, and probably hard to delay |
dantro.utils |
1600 |
|
dantro.utils.data_ops |
320 | self-time is 10ms, so it's not from the definition itself |
dantro._yaml |
1250 |
xarray and networkx
|
dantro._dag_utils |
410 | ... most of which for sympy |
networkx |
270 | easy to delay |
xarray |
810 | hard to delay, given that paramspace imports it |
pkg_resources |
130 | not super bad, and probably hard to delay |
Proposal
Delay package imports of:
- sympy
- networkx
- seaborn
We can simply do so by moving the import
statements to where the modules are actually needed.
Edited by Utopia Developers