Skip to content

GH-101362: Optimise pathlib by deferring path normalisation#101560

Closed
barneygale wants to merge 16 commits intopython:mainfrom
barneygale:optimize-pathlib-part-2b
Closed

GH-101362: Optimise pathlib by deferring path normalisation#101560
barneygale wants to merge 16 commits intopython:mainfrom
barneygale:optimize-pathlib-part-2b

Conversation

@barneygale
Copy link
Contributor

@barneygale barneygale commented Feb 4, 2023

PurePath now normalises and splits paths only when necessary, e.g. when .name or .parent is accessed. The result is cached. This speeds up path object construction by around 4x.

PurePath.__fspath__() now returns an unnormalised path, which should be transparent to filesystem APIs (else pathlib's normalisation is broken!). This extends the earlier performance improvement to most impure Path methods, and also speeds up p.joinpath('bar') and p / 'bar'. edit: will fix separately.

This also fixes GH-76846 and GH-85281 by unifying path constructors and adding an __init__() method. edit: will fix separately.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pathlib.Path._from_parsed_parts should call cls.__new__(cls)

3 participants