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

Initialise backend on first use instead of on import #480

Merged
merged 2 commits into from Dec 22, 2020

Conversation

takluyver
Copy link
Contributor

@takluyver takluyver commented Dec 11, 2020

This seems so simple I kind of think I must be missing something, but tox passes on my (Linux) system.

Doing complicated stuff on import is generally best avoided, because we typically assume that imports are fast and reliable. This simply defers selecting and initialising a backend to the first time any of the public API functions are called. The only possible negative impact I can think of is if the environment changes between import and first use, it may lead to using a different backend. But it's hard to come up with realistic cases where that would be a problem, and if it is, the caller can use get_keyring() to initialise the backend early.

Closes #403.

@takluyver
Copy link
Contributor Author

@jaraco can I interest you in this? The actual diff is pretty small.

@jaraco
Copy link
Owner

jaraco commented Dec 22, 2020

I like it. Yeah, let's do it.

@jaraco jaraco merged commit 0f2d42b into jaraco:main Dec 22, 2020
@jaraco
Copy link
Owner

jaraco commented Dec 22, 2020

Releasing as 21.6.

@takluyver takluyver deleted the defer-init-backend branch December 22, 2020 16:24
@takluyver
Copy link
Contributor Author

Thanks! 🤞 this doesn't break everything. 😉

@jyn514
Copy link
Contributor

jyn514 commented Dec 22, 2020

Wow, this really made an enormous difference ❤️ With the same commands as #403 (comment) this brought the import time down from 2 seconds to 200 milliseconds :) with a hot disk cache it's only 35 milliseconds.

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

Successfully merging this pull request may close these issues.

Improve import times
3 participants