[Python-Dev] To reduce Python "application" startup time

Terry Reedy tjreedy at udel.edu
Tue Sep 5 13:52:28 EDT 2017

On 9/5/2017 9:02 AM, INADA Naoki wrote:

> But application startup time is more important.  And we can improve
> them with optimize importing common stdlib.
> Current `python -v` is not useful to optimize import.
> So I use this patch to profile import time.
> https://gist.github.com/methane/e688bb31a23bcc437defcea4b815b1eb
> With this profile, I tried optimize `python -c 'import asyncio'`, logging
> and http.client.
> https://gist.github.com/methane/1ab97181e74a33592314c7619bf34233#file-0-optimize-import-patch
> With this small patch:
> logging: 14.9ms -> 12.9ms
> asyncio: 62.1ms -> 58.2ms
> http.client: 43.8ms -> 36.1ms
> I haven't created pull request yet.
> (Can I create without issue, as trivial patch?)

Trivial, no-issue PRs are meant for things like typo fixes that need no 
discussion or record.

Moving imports in violation of the PEP 8 rule, "Imports are always put 
at the top of the file, just after any module comments and docstrings, 
and before module globals and constants", is not trivial.  Doing so 
voluntarily for speed, as opposed to doing so necessarily to avoid 
circular import errors, is controversial.

Terry Jan Reedy

More information about the Python-Dev mailing list