Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkyCoord slow to import #5222

Closed
sdjohnson-astro opened this issue Aug 7, 2016 · 21 comments
Closed

SkyCoord slow to import #5222

sdjohnson-astro opened this issue Aug 7, 2016 · 21 comments

Comments

@sdjohnson-astro
Copy link

I recently wrote a few command line tools for converting coordinates but found that they are noticeably slow to run. The runtime is dominated by importing SkyCoord from astropy.coordinates which takes nearly 2 seconds (for reference, this is a new installation of astroconda running on my MacBook Pro retina w/ 2.7 GHz i7 processor, 16 GB of ram, and an SSD). For comparison, imports from standard libraries such as numpy or UnivariateSpline from scipy.interpolate takes ~0.15 seconds. Is there any way to speed up the import of SkyCoord?

@MSeifert04
Copy link
Contributor

@sdjohnson-astro Which version of astropy do you use? The import time was sped up for astropy 1.2 but it's still not as fast as numpy/scipy.

See also #4598.

@sdjohnson-astro
Copy link
Author

I am using Astropy version 1.2.1

Thanks for the super fast reply!

@pllim
Copy link
Member

pllim commented Aug 8, 2016

Like @MSeifert04 said, there is already a related issue like this. What if you simply do import astropy? Is it the same kind of slowness?

@sdjohnson-astro
Copy link
Author

import astropy takes 0.5 seconds. Significantly faster than the 2 seconds it takes to import SkyCoord from astropy.

@pllim
Copy link
Member

pllim commented Aug 8, 2016

If you are feeling adventurous, you can profile the offending import statement and post some results here. See https://docs.python.org/3/library/profile.html

@pllim
Copy link
Member

pllim commented Aug 8, 2016

And to make sure that this is not already solved since the release, you can also try the dev version from master.

@astrofrog
Copy link
Member

@sdjohnson-astro - can you test import astropy.units?

@MSeifert04
Copy link
Contributor

Just for convenience these import times can be tested from the command line with
python -m timeit -n 1 -r 1 "from astropy.coordinates import SkyCoord" (which takes 5-6s on my machine)

@pllim
Copy link
Member

pllim commented Aug 8, 2016

Interesting. Using the latest dev myself. The first time I run @MSeifert04 's command, it took 4.83 sec. But subsequent calls was about 1.87 sec each.

@pllim
Copy link
Member

pllim commented Aug 8, 2016

@astrofrog , python -m timeit -n 1 -r 1 "import astropy.units" gave me about 925 msec. But that is after I already ran the SkyCoord import test several times.

@sdjohnson-astro
Copy link
Author

Thanks for the tip.

@astrofrog importing astropy.units takes 0.8 seconds on my laptop.

I don't know enough about astropy to make much of the profiling results at first glance. The profile results are attached if anyone wants to take a look.
SkyCoord_profile.txt

I will try out the latest dev myself, but from @pllim it looks like the import time is still non-negligible.

@MSeifert04
Copy link
Contributor

@pllim The first time python encounteres new .py files it generates __pycache__ and .pyc files. This will account for the longish "first" import.

@pllim
Copy link
Member

pllim commented Aug 8, 2016

@sdjohnson-astro , thanks for the log. But it is hard to diagnose without full path to the filenames, and would be nice to sort them by cumtime.

@sdjohnson-astro
Copy link
Author

@pllim A version sorted by cumulative time is attached. I am not sure how to get the full path to filenames with cProfile. Is there an option in the documentation that I am missing?

Thanks!

import_SkyCoord_profile.txt

@pllim
Copy link
Member

pllim commented Aug 8, 2016

Thanks, @sdjohnson-astro . I think the listed filenames are unique enough that we don't need the full path. From your log:

        1    0.001    0.001    1.505    1.505 baseframe.py:6(<module>)
        1    0.000    0.000    1.500    1.500 earth.py:2(<module>)
        1    0.003    0.003    1.499    1.499 __init__.py:25(<module>)
        1    0.000    0.000    1.448    1.448 fk5.py:3(<module>)
        1    0.000    0.000    1.418    1.418 utils.py:6(<module>)
        1    0.001    0.001    1.417    1.417 iers.py:10(<module>)

Maybe @eteq or @taldcroft wish to chime in?

@sdjohnson-astro
Copy link
Author

@pllim Importing SkyCoord also takes 2 seconds on my computer when using the latest 'dev'.

@pllim
Copy link
Member

pllim commented Aug 9, 2016

@sdjohnson-astro , thanks for checking! I see iers.py listed. I wonder if it is something to do with some kind of initialization there...

@eerovaher
Copy link
Member

I ran the following with the current astropy development version (0e379d8):

python -X importtime -c "from astropy.coordinates import SkyCoord"
python -X importtime -c "import numpy"

The difference in the reported times was roughly a factor of 3, much less than the more than an order of magnitude difference reported in this issue. I haven't bothered looking up any commits that might have contributed towards faster importing, but it does seem like this issue is no longer relevant.

@sdjohnson-astro
Copy link
Author

sdjohnson-astro commented Nov 15, 2022 via email

@github-actions
Copy link

Hi humans 👋 - this issue was labeled as Close? approximately 6 hours ago. If you think this issue should not be closed, a maintainer should remove the Close? label - otherwise, I will close this issue in 7 days.

If you believe I commented on this issue incorrectly, please report this here

@github-actions
Copy link

I'm going to close this issue as per my previous message, but if you feel that this issue should stay open, then feel free to re-open and remove the Close? label.

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants