Hi Barry,

On Fri, Apr 8, 2022 at 12:44 PM Barry Warsaw <ba...@python.org> wrote:
>
> Start up overhead due to imports is a real problem for some class of 
> applications, e.g. CLIs, and I’ve seen a lot of hacks implemented to get 
> Python CLIs to be more responsive.  E.g. getting from invocation to —help 
> output is a major UX problem.

Definitely, we have this same problem, and also the same symptom of
people pushing hard to rewrite Python CLIs in Go for this reason.

> It’s often more complicated than just imports alone though.  Expensive module 
> scope initializations and decorators contribute to this problem.

One of our projects that can prevent much of this expensive work being
done at import time is Strict Modules[1]. Currently it's only
available as part of Cinder, though we're hoping to make it
pip-installable as part of our project to make Cinder's features more
easily accessible.

Our experience in practice, though, has been that universally lazy
imports is somewhat easier to adopt than Strict Modules, and has had a
much bigger overall impact on reducing startup time for big CLIs (and
a big web server too; as you note it's not as serious an issue for a
web server in production, but restart time still does make a
difference to dev speed / experience.) Removing slow stuff happening
at import time helps, but it'll never match the speed of not doing the
import at all! We've seen startup time improvements up to 70% in
real-world CLIs just by making imports lazy. We've also opened an
issue to discuss the possibility of upstreaming this. [2]

[1] https://github.com/facebookincubator/cinder/#strict-modules
[2] https://bugs.python.org/issue46963
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/62OTFJMAMQ2WHZ4H3TUEJTECMPJDQ557/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to