New submission from Nick Coghlan <ncogh...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue33440>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to