[New-bugs-announce] [issue33440] Possible lazy import opportunities in `pathlib`

Nick Coghlan report at bugs.python.org
Mon May 7 08:28:40 EDT 2018


New submission from Nick Coghlan <ncoghlan at gmail.com>:

Due to a python-ideas discussion about reducing boilerplate for __file__-relative path calculations, I was running "./python -X importtime -S -c 'import pathlib'" and noticed three potential candidates where it may be worthwhile deferring the imports until the modules are actually needed:

- re (used in _WildcardSelector)
- fnmatch (used in PurePath.match and _WildcardSelector)
- urllib.parse (used in PurePath.as_uri, by way of self._flavour.make_uri)

Using an optimised Python 3.7 on an SSD with warm disk caches, commenting out those 3 imports reduced my typical import times for pathlib from 12-13 ms to 7-8 ms)

----------
components: Library (Lib)
messages: 316266
nosy: ncoghlan, njs, pitrou
priority: normal
severity: normal
status: open
title: Possible lazy import opportunities in `pathlib`
type: performance
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33440>
_______________________________________


More information about the New-bugs-announce mailing list