Slow runserver start up, how to debug

My project has grown over time, and now when I issue runserver, or when I changed a file, it takes about 5 seconds to get going again. Which is not great when one makes a changed, alt tabs to the browser hits refresh, and it fails, because the server is reloaded.

How can I try figure out what is delaying the project start up?

Python’s -X importtime flag can help you see the time to import various modules. The tool importtime-waterfall can help you visualize its output. The author has a video walking through using it on a real project: how I sped up python by 20ms (intermediate) anthony explains #417 - YouTube

2 Likes

This is how you use importtime-waterfall with Django: Django: How to profile and improve startup time - Adam Johnson

I could split my Django project’s startup time in half by converting a few rarely used imports into local imports, like PDF generation, XSLX reading and writing, and Office 365 connection.