As an email user on Discourse, I’ve noticed that quoting seems to get
stripped. Apologies if that happens again.
[steven.daprano] Steven D’Aprano
https://discuss.python.org/u/steven.daprano steven.daprano
December 7
Pushing the lazy choice to the library maintainers sounds correct.
How do you reason that?
The library is either tiny or large. If tiny, there is little
difference between eager and lazy loads regarding performance.
If large, then whatever needs to be done to defer the cost past startup
seems worth the cost. But it is the library author that has to code
support for lazy loading. What I hear in the discussion is that lazy
loading changes semantics somewhat, and the library may not work if
loaded lazily, apparently due to several technical issues, some of which
seem to be able to be worked around externally, and some not (or the
cost of doing so is too high in complexity or performance). Hence, the
attempt to lazy load some libraries has been stated to fail, and to
cause library maintainers to be potentially inundated with feature
requests to support lazy loading.
If it were the library maintainers that made the decision to do the work
to support lazy loading (automatically, instead of by application
request), then they could promote that as a competitive advantage versus
libraries that do not support lazy loading.
It also would mean that no changes would be necessary to the
applications to benefit from the performance gains, other than using the
upgraded version of the library that supports lazy loading, which is
simple. There has been much discussion about needing to update all the
applications with the new syntax, for various lazy loading proposals,
and that applications wouldn’t all benefit.
The library author does not and can not know the caller’s requirements.
It is the caller, not the library, who knows whether eagerly loading the
library at startup is too expensive. It is the caller, not the library,
that can choose to delay loading the library by moving the import into a
function.
The library knows how big it is, and how expensive it is to have itself
loaded, and whether or not lazy loading would be a benefit.