soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
445 stars 131 forks source link

FYI trackpy import times #604

Closed apiszcz closed 4 years ago

apiszcz commented 4 years ago

Reviewing startup times on python programs i am seeing the longest module load times from trackpy. This may be my environment or some other local issue. trackpy is taking 8,785,844 microseconds to load. Python 3.7 reports import times by using python -X importime yourprogram.py

import time | 12725 | 2552582 | trackpy.try_numba
-- | -- | -- | --
import time | 1429 | 1429 | trackpy.linking.utils
import time | 1758 | 1758 | trackpy.linking.subnet
import time | 1968 | 1968 | trackpy.linking.subnetlinker
import time | 30712 | 2588447 | trackpy.linking.linking
import time | 1461 | 1461 | trackpy.linking.partial
import time | 3607 | 3607 | trackpy.refine.center_of_mass
import time | 23709 | 23709 | numdifftools
import time | 8553 | 32262 | trackpy.refine.least_squares
import time | 1569 | 1569 | trackpy.refine.brightfield_ring
import time | 34480 | 71917 | trackpy.refine
import time | 1386 | 1386 | trackpy.uncertainty
import time | 12474 | 13859 | trackpy.feature
import time | 16093 | 101868 | trackpy.linking.find_link
import time | 1847 | 1847 | trackpy.linking.legacy
import time | 34188 | 2727810 | trackpy.linking
import time | 1505 | 1505 | trackpy.filtering
import time | 1625 | 1625 | trackpy.framewise_data
import time | 2080 | 2080 | trackpy.locate_functions.brightfield_ring
import time | 13515 | 15594 | trackpy.locate_functions
import time | 2890 | 2890 | trackpy.predict
import time | 1749 | 1749 | trackpy.artificial
import time | 59621 | 8769458 | trackpy.api
import time | 14925 | 8785844 | trackpy

2020-04-18T171915_683_261

Trackpy is the highest peak around x=2600. 2020-04-18T172352_1019_382

nkeim commented 4 years ago

Thanks for posting this. I wasn't aware of importtime. 8.7 s does seem like a lot. On my humble laptop (the base-model 2016 MacBook Pro), trackpy takes about 1.6 s, so perhaps there is something else going on.

On my system, and in the sample you pasted, it looks like the trackpy modules themselves have reasonably short load times; it's just that import trackpy also imports a huge swath of the scientific Python and image I/O ecosystem, that many people would use anyway even if they didn't use trackpy. Pandas, numpy, scipy, matplotlib, IPython, and numba alone account for more than half of the time. That said, that's not true in every use case—there are applications of trackpy that don't require matplotlib or pims, for example.

Here's the output of python -X importtime -c 'import trackpy' 2> importtime.txt: importtime.txt