Yes, you would incur the delay when the package is finally imported.

But consider the case where you are importing multiple packages, all at
start-up. For this example, say there are four import which take ½ second
each. This would add 2 seconds to the start-up. Very noticeable by the user.

If the first use of each imported package happens at different points in
the program's progress, with lazy loading the delay would only be ½ second
every once in a while.  Much less noticeable by the user.

The same total amount of load time, but spread over a longer period of time.

On Fri, Mar 27, 2026, 4:33 PM Thomas Passin <[email protected]> wrote:

> On 3/27/2026 2:09 PM, Piergiorgio Sartor wrote:
> > On 26/03/2026 02.40, Lawrence D’Oliveiro wrote:
> >> So Python 3.15 will introduce a new, “lazy” import mechanism
> >> <https://peps.python.org/pep-0810/>.
> >>
> >> So far I have done one script where I moved an import into the
> >> function where it was used, instead of doing it globally; this reduced
> >> the script startup time from around 1.5 seconds down to about a
> >> quarter second.
>
> But when it does get imported, you would incur the same delay, right?
>
> >> “Lazy” imports would avoid the need for such workarounds, while
> >> keeping all imports together so they can be found more easily.
> >
> > Interesting, I needed this as well.
> > Last time I checked, the suggestion
> > was rejected...
> >
> > Good if they changed their mind.
> >
> > bye,
> >
>
> --
> https://mail.python.org/mailman3//lists/python-list.python.org
>
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to