2026-09-03 –, Auditorium
A couple of slow imports made our Django development miserable. Inlining imports fixed the speed but hurt the codebase. Explicit lazy imports in Python 3.15 will finally give us the speed without the mess!
Python's import system runs eagerly: every import statement executes the module you are importing from top to bottom, and this includes executing all the nested imports. For command-line tools like Django's management commands, this can result in a multi-second wait. For our project, this resulted in 10+ second wait times on every command, including every server restart, due to a few bad imports scattered around the codebase.
In the talk, we'll briefly explain how the import system works, how to find imports that take a long time, and explain why the slowest import was so slow.
We'll then look at how using lazy imports reduced our management commands from 10 seconds to less than 3 seconds, but also how our codebase ended up looking worse as a result. We'll also look at how to ensure we don't accidentally make end users pay for lazy imports during the request/response cycle, and how we made sure it's not possible to regress by adding a lint check.
Finally, we'll look at how, in Python 3.15, all of this will become much easier thanks to PEP 810: Explicit lazy imports.
Django, performance, imports, development experience
I write code and surf waves
