<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, 23 Jun 2017 at 12:17 Bhavishya <<a href="mailto:bhavishyagopesh@gmail.com">bhavishyagopesh@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>As suggested, I'd like to discuss if lazy-loading is an
option for improving python-startup time.And if could be done inside the
scope of a GSoc project.</div></div></div></div></blockquote><div><br></div><div>It's a possibility and it could be done in the scope of a GSoC project easily. Basically what would be needed is an importlib.util.lazy_import() function which does mostly what is outlined in <a href="https://docs.python.org/3/library/importlib.html#approximating-importlib-import-module">https://docs.python.org/3/library/importlib.html#approximating-importlib-import-module</a> but where the proper lazy loader is set on the spec object as an extra step. Then every module that is used during startup would use importlib.util.lazy_import() for importing instead of the normal import statement. What this would do is help guarantee that all modules that are identified as part of startup never import a module needlessly as the lazy loader would simply postpone the load until necessary. This would also allow for pulling out local imports that are currently done in modules that are a part of startup and make them global so they are more visible.</div><div><br></div><div>But I have no idea if this will actually speed things up. :) At worst it would slow things down ever so slightly due to the extra overhead of lazy loading for things that are known to be needed already during startup. At best, though, is we accidentally discover modules that are being imported needlessly at startup as well as not having to hide imports in functions for performance. This fact that it may not be worth it is why I haven't bothered to try it out yet.</div></div></div>