Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up pathlib by removing a few temporary objects #112361

Closed
barneygale opened this issue Nov 24, 2023 · 0 comments
Closed

Speed up pathlib by removing a few temporary objects #112361

barneygale opened this issue Nov 24, 2023 · 0 comments
Labels
performance Performance or resource usage topic-pathlib

Comments

@barneygale
Copy link
Contributor

barneygale commented Nov 24, 2023

A handful of pathlib methods that create paths with modified names, or additional segments, use list objects that are quickly thrown away. We can speed these methods up by only creating new lists where strictly necessary.

Specifically:

  • with_name() (performance of self._tail[:-1] + [name] is cursed)
  • with_suffix()
  • _make_child_relpath() (used in glob() and walk())
  • glob() (when parsing the pattern)

Linked PRs

@barneygale barneygale added performance Performance or resource usage topic-pathlib labels Nov 24, 2023
barneygale added a commit to barneygale/cpython that referenced this issue Nov 24, 2023
Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()`, `with_suffix()`, `_make_child_relpath()` (used in walking
and globbing), and `glob()`.
barneygale added a commit that referenced this issue Nov 25, 2023
)

Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()` and `with_suffix()`
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…python#112362)

Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()` and `with_suffix()`
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…python#112362)

Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()` and `with_suffix()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage topic-pathlib
Projects
None yet
Development

No branches or pull requests

1 participant