Mailing List Archive

PEP 690: Lazy Imports
Hello,

PEP 690 <https://peps.python.org/pep-0690/> is now live! It proposes an
exciting new feature to transparently defer the execution of imported
modules until the moment when an imported object is used. Since Python
programs commonly import many more modules than a single invocation of the
program is likely to use in practice, lazy imports can greatly reduce the
overall number of modules loaded, improving startup time and memory usage.

At Meta, we have implemented this feature in Cinder
<https://github.com/facebookincubator/cinder>, and has already demonstrated
<https://github.com/facebookincubator/cinder/blob/cinder/3.8/CinderDoc/lazy_imports.rst>
startup time improvements up to 70% and memory-use reductions up to 40% on
real-world Python CLIs, while also eliminating the risk for most import
cycles.

Please, don't reply to this message. Feel free to comment or share thoughts
and feedback in Python Discourse
<https://discuss.python.org/t/pep-690-lazy-imports> at
https://discuss.python.org/t/pep-690-lazy-imports.

Best,
Germán

---

Relevant links follow:

https://peps.python.org/pep-0690
https://github.com/facebookincubator/cinder
https://github.com/facebookincubator/cinder/blob/cinder/3.8/CinderDoc/lazy_imports.rst
https://discuss.python.org/t/pep-690-lazy-imports