Repository navigation
Closed
Description
UltraPlot has a lot of greedy imports (see for example the * imports in __init__.py), we could reduce the import time by making modules available on demand rather than importing everything greedily. For an overview of the import time I used pyinstrument to identify "hot" spots
⮞ pyinstrument import.py
_ ._ __/__ _ _ _ _ _/_ Recorded: 10:57:43 Samples: 572
/_//_/// /_\ / //_// / //_'/ // Duration: 1.217 CPU time: 2.444
/ _/ v5.1.1
Program: import.py
1.217 <module> import.py:1
└─ 1.217 <module> ultraplot/__init__.py:1
├─ 0.628 <module> ultraplot/internals/__init__.py:1
│ ├─ 0.314 <module> ultraplot/internals/docstring.py:1
│ │ ├─ 0.232 <module> matplotlib/axes/__init__.py:1
│ │ │ [18 frames hidden] matplotlib
│ │ └─ 0.080 <module> matplotlib/figure.py:1
│ │ [10 frames hidden] matplotlib, mpl_toolkits
│ ├─ 0.116 <module> matplotlib/__init__.py:1
│ │ [7 frames hidden] matplotlib, pyparsing, PIL
│ ├─ 0.113 <module> numpy/__init__.py:1
│ │ [15 frames hidden] numpy, typing
│ └─ 0.073 <module> ultraplot/internals/inputs.py:1
│ └─ 0.073 <module> cartopy/__init__.py:1
│ [7 frames hidden] cartopy, pyproj, urllib, http
├─ 0.307 <module> ultraplot/config.py:1
│ ├─ 0.289 <module> IPython/__init__.py:1
│ │ [35 frames hidden] IPython, prompt_toolkit, jedi, stack_...
│ └─ 0.014 Configurator.__init__ ultraplot/config.py:789
│ └─ 0.014 Configurator._init ultraplot/config.py:891
├─ 0.076 <module> mpl_toolkits/basemap/__init__.py:1
│ ├─ 0.036 [self] mpl_toolkits/basemap/__init__.py
│ └─ 0.014 str.strip <built-in>
├─ 0.056 <module> ultraplot/axes/__init__.py:1
│ └─ 0.028 <module> ultraplot/axes/cartesian.py:1
│ └─ 0.021 <module> ultraplot/axes/plot.py:1
│ └─ 0.019 PlotAxes ultraplot/axes/plot.py:1534
│ └─ 0.019 _concatenate_inherited ultraplot/internals/docstring.py:62
├─ 0.056 register_colors ultraplot/config.py:578
│ └─ 0.052 _standardize_colors ultraplot/colors.py:710
│ └─ 0.048 to_xyz ultraplot/utils.py:681
│ └─ 0.046 to_xyza ultraplot/utils.py:708
│ ├─ 0.028 to_rgba ultraplot/utils.py:615
│ └─ 0.018 rgb_to_hcl ultraplot/externals/hsluv.py:106
│ └─ 0.016 rgb_to_CIExyz ultraplot/externals/hsluv.py:263
├─ 0.028 <module> matplotlib/pyplot.py:1
│ [5 frames hidden] matplotlib
└─ 0.018 <module> ultraplot/ticker.py:1
└─ 0.014 <module> cartopy/mpl/ticker.py:1
└─ 0.014 <module> cartopy/mpl/geoaxes.py:1
To view this report with different options, run:
pyinstrument --load-prev 2025-10-30T10-57-43 [options]Metadata
Metadata
Assignees
Labels
No labels
Activity
cvanelteren commentedon Oct 30, 2025
The priority is rather low on fixing this, but would be worth taking a look at. The majority of high import times are due to aggressively importing matplotlib in modules that rarely use it. Jupyter users will probable not notice the delay much, but drawing figure from the command line does feel a bit sluggish.