42.9 Lazy Imports and Import Performance
In Python, the import statement is executed eagerly at the point of encounter. While this is straightforward and predictable, it can lead to significant performance bottlenecks at application startup, especially when importing large modules or many modules that are not immediately needed. Lazy import strategies defer the loading of a module’s code and the execution of its top-level statements until the moment a name from that module is actually accessed. This can dramatically improve startup time and reduce initial memory footprint, though it may shift the import cost to later during runtime execution.