Skip to content

pymatviz import cost way too high #209

Closed
@janosh

Description

@janosh

takes almost 2 seconds to import the latest version of pymatviz. used to be a lot less. i suspect #194 may have caused this problem without me noticing at the time. current import waterfall can be generated with:

time python -X importtime -c 'import pymatviz'
...
fraction
import time:       157 |        157 |       pymatgen.analysis.diffraction.core
import time:       624 |        966 |     pymatgen.analysis.diffraction.xrd
import time:       276 |       1241 |   pymatviz.xrd
import time:       175 |        175 |   pymatviz.histogram
import time:       992 |    2308598 | pymatviz
python -X importtime -c 'import pymatviz'  1.88s user 0.33s system 82% cpu 2.705 total

should figure out which modules take the longest to load, and decide if they really need to be imported from pymatviz/__init__.py or if they could be lazy-loaded instead (i.e. only loaded if the user actually accesses them) and put some regression tests in place to ensure no future PRs blow up the import time again. might also make sense to see how large code bases like pandas keep their import time low

Metadata

Metadata

Assignees

Labels

pkgPackageuxUser experience

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions