FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-117586: Speed up `pathlib.Path.walk()` by working with strings by barneygale · Pull Request #117726 · python/cpython · GitHub

Repository navigation

GH-117586: Speed up pathlib.Path.walk() by working with strings - #117726

Merged
barneygale merged 1 commit into
python:mainfrom
barneygale:also-move-walk
Apr 11, 2024
Merged

barneygale merged 1 commit into
python:mainfrom
barneygale:also-move-walk

Conversation

barneygale commented Apr 10, 2024 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Move pathlib.Path.walk() implementation into glob._Globber. The new glob._Globber.walk() classmethod works with strings internally, which is a little faster than generating Path objects and keeping them normalized. The pathlib.Path.walk() method converts the strings back to path objects.

In the private pathlib ABCs, our existing subclass of _Globber ensures that PathBase instances are used throughout.

Follow-up to #117589.

Timings:

$ ./python -m timeit -s "from pathlib import Path; p = Path.cwd()" "list(p.walk())"
10 loops, best of 5: 29.8 msec per loop  # before
10 loops, best of 5: 28.9 msec per loop  # after
# --> 1.03x faster

Speedup is nothing to write home about, but this PR has the benefit of keeping closely-related recursive-directory-walking code together, and removing some redundant private pathlib methods.

Move `pathlib.Path.walk()` implementation into `glob._Globber`. The new
`glob._Globber.walk()` classmethod works with strings internally, which is
a little faster than generating `Path` objects and keeping them normalized.
The `pathlib.Path.walk()` method converts the strings back to path objects.

In the private pathlib ABCs, our existing subclass of `_Globber` ensures
that `PathBase` instances are used throughout.

Follow-up to python#117589.
barneygale added performance Performance or resource usage topic-pathlib labels Apr 10, 2024
barneygale merged commit 0cc71bd into python:main Apr 11, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…gs (python#117726)

Move `pathlib.Path.walk()` implementation into `glob._Globber`. The new
`glob._Globber.walk()` classmethod works with strings internally, which is
a little faster than generating `Path` objects and keeping them normalized.
The `pathlib.Path.walk()` method converts the strings back to path objects.

In the private pathlib ABCs, our existing subclass of `_Globber` ensures
that `PathBase` instances are used throughout.

Follow-up to python#117589.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL