|
|
|
|
|
by nsm
858 days ago
|
|
Related to this, if you set the env var `PYTHONPROFILEIMPORTTIME=1` or run python with `-X importtime`, it will print out the cumulative and self times to import various modules. There is then this neat tool to visualize the data. https://kmichel.github.io/python-importtime-graph/ Highly recommend to find the worst imports affecting your program startup time. In general, the python community values tend towards functionality over performance. For example, large modules (looking at networkx here) will often import a bunch of there submodules in their __init__.py, which means all modules now end up loaded even if you didn't need them. I've never tried https://pyoxidizer.readthedocs.io/en/stable/oxidized_importe..., but it compiles all the imports into one, memory mapped file, that _may_ speed up the importing. Having everything compiled to bytecode also helps a bunch. |
|