This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients berker.peksag, martin.panter, orsenthil, piyush-kgp
Date 2019-04-23.08:57:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556009832.53.0.950260701474.issue36701@roundup.psfhosted.org>
In-reply-to
Content
The “urllib” package also contains “urllib.parse”, which is a lot more lightweight than “urllib.request”. In a quick experiment, importing “urllib.request” is more than 2 times slower than importing “urllib.parse” on its own. And importing “urllib” by itself is not much faster, so I guess a lot of the time is unavoidable Python startup, and “urllib.request” is probably many times slower than “urllib.parse”.

The reason for the slowness is the dependencies and initialization. The “urllib.parse” module only imports a few commonly-used modules. On the other hand, importing “urllib.request” imports many heavyweight high-level modules directly and indirectly (email submodules in particular, also things like SSL, multithreading, HTTP client, temporary files). Some of these dependencies also compile lots of regular expressions at import time.

The slowdown can be a problem for things like command-line programs. Just today I found “circusd --help” on a Raspberry Pi took ~5 s to produce output.

The case of “os.path” is different: it isn’t a submodule of “os”. It is just a pointer to “posixpath”, “ntpath”, etc, depending on “os.name”.
History
Date User Action Args
2019-04-23 08:57:12martin.pantersetrecipients: + martin.panter, orsenthil, berker.peksag, piyush-kgp
2019-04-23 08:57:12martin.pantersetmessageid: <1556009832.53.0.950260701474.issue36701@roundup.psfhosted.org>
2019-04-23 08:57:12martin.panterlinkissue36701 messages
2019-04-23 08:57:12martin.pantercreate