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

import sgkit takes ~1.5s #931

Open
benjeffery opened this issue Oct 14, 2022 · 7 comments
Open

import sgkit takes ~1.5s #931

benjeffery opened this issue Oct 14, 2022 · 7 comments

Comments

@benjeffery
Copy link
Collaborator

For tools using the CLI this amount of delay feels excessive. Around 1s of this time is performing imports. Here's the import flame graph:
(0.1s on xarray.tutorial?!?)

sgkit-import-profile

I assume some of these could be imported only when they are needed - although given that many of the imports are referenced in typing specifications that might not be possible.

I'm not sure yet what the remaining 0.5s is - a cProfile callgraph is pretty useless on import but I think there is a way around that by profiling the individual sgkit files.

@tomwhite
Copy link
Collaborator

I agree that deferring some of the imports could help.

I think numba compilation is still a significant part of this, see #363, although we now have numba caching on so it's faster the second time. Not sure if we could defer this until it's needed too.

@benjeffery
Copy link
Collaborator Author

Thanks @tomwhite I'll check the numba compilation.
I also wonder if PEP484 forward references might help with delaying imports: https://legacy.python.org/dev/peps/pep-0484/#forward-references

@tomwhite
Copy link
Collaborator

I also wonder if PEP484 forward references might help with delaying imports: https://legacy.python.org/dev/peps/pep-0484/#forward-references

It would be great if we could take advantage of forward references.

Do you think xarray itself is doing unnecessary imports - like the tutorial?

@benjeffery
Copy link
Collaborator Author

benjeffery commented Oct 17, 2022

Do you think xarray itself is doing unnecessary imports - like the tutorial?

Yes, planning on checking and raising a PR/issue upstream, unless it looks like a rabbit-hole!

@benjeffery
Copy link
Collaborator Author

Also see pydata/xarray#6726, seems they are aware of the issue.

@jeromekelleher
Copy link
Collaborator

If we're importing some things just for typing purposes, then I'd be +1 for making the typing less strict.

@tomwhite
Copy link
Collaborator

Pandas is not used very much in the codebase, so it might be possible to import it lazily.

Similarly, the distance API is pretty niche so making that lazier would be good too.

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

No branches or pull requests

3 participants