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

Lazily import django.test to reduce import time #1084

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

angusholder
Copy link
Contributor

I was running a flamegraph on our manage.py, and noticed this import of django.test using 20-40ms. Seems like an easy win for startup time to make it a lazy import, because most production code wouldn't normally ever need the django.test module.

@adamchainz
Copy link
Owner

Thanks, that is an easy win. I added a changelog note and improved the comment.

This function could be improved further to not use django.test and instead capture the query with database instrumentation, if you’re up for the challenge.

@adamchainz adamchainz changed the title Lazily import django.test to reduce startup time Lazily import django.test to reduce import time Apr 26, 2024
@adamchainz adamchainz merged commit 07a5edc into adamchainz:main Apr 26, 2024
33 checks passed
@angusholder angusholder deleted the patch-1 branch April 26, 2024 13:00
@angusholder
Copy link
Contributor Author

After sending this, I realised it was your blog posts I read recently about improving Django start time, so thanks for those!

Might have a go at that database instrumentation change later, I haven't seen it before, looks interesting.

@adamchainz
Copy link
Owner

Glad you enjoyed them!

I also have some blog posts on database instrumentation that may inform: https://duckduckgo.com/?t=ffab&q=site%3Aadamj.eu+%22database+instrumentation%22&ia=web

The suggestion is just an “if you’re interested”, I don't use pt_visual_explain myself, at the moment, and I guess you don’t either :)

adamchainz added a commit that referenced this pull request Jun 19, 2024
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.

2 participants