Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-112361: Speed up pathlib by removing some temporary objects.#112362

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commentedNov 24, 2023
edited by bedevere-appbot
Loading

Construct only one new list object (usinglist.copy()) when creating a new path object with a modified tail. This slightly speeds upwith_name(),with_suffix(),_make_child_relpath() (used in walking and globbing), andglob().

Construct only one new list object (using `list.copy()`) when creating anew path object with a modified tail. This slightly speeds up`with_name()`, `with_suffix()`, `_make_child_relpath()` (used in walkingand globbing), and `glob()`.
@barneygale
Copy link
ContributorAuthor

Timings:

$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo')" "p.with_name('bar')"1000000 loops, best of 5: 1.44 usec per loop  # before1000000 loops, best of 5: 1.31 usec per loop  # after$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo.txt')" "p.with_suffix('.zip')"1000000 loops, best of 5: 2.02 usec per loop  # before1000000 loops, best of 5: 1.83 usec per loop  # after$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo.txt')" "p.with_suffix('')"1000000 loops, best of 5: 1.88 usec per loop  # before1000000 loops, best of 5: 1.68 usec per loop  # after$ ./python -m timeit -n 1000000 -s "from pathlib import Path; p = Path('foo')" "p._make_child_relpath('bar')"1000000 loops, best of 5: 1.14 usec per loop  # before1000000 loops, best of 5: 1.11 usec per loop  # after

Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Overall this looks really nice -- great work! I can reproduce the big speedups from the first three benchmarks in#112362 (comment).

Ican't repro the reported speedup for_make_child_relpath, though (the fourth benchmark from#112362 (comment)) -- if anything, it looks like this PR makes it slightlyslower for me locally? (I'm on Windows with a fresh PGO-optimised build frommain.)

barneygale reacted with thumbs up emoji
@barneygale
Copy link
ContributorAuthor

Ican't repro the reported speedup for_make_child_relpath, though (the fourth benchmark from#112362 (comment)) -- if anything, it looks like this PR makes it slightlyslower for me locally? (I'm on Windows with a fresh PGO-optimised build frommain.)

Hm. With a fresh PGO rebuild on Linux I still see an improvement, but it's really marginal - only 2% faster. I'll take the change out of the PR.

AlexWaygood reacted with thumbs up emoji

Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks great, thanks!

barneygale reacted with hooray emoji
@barneygale
Copy link
ContributorAuthor

Thank you for the review Alex!

AlexWaygood reacted with rocket emoji

aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
…python#112362)Construct only one new list object (using `list.copy()`) when creating anew 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 pull requestSep 2, 2024
…python#112362)Construct only one new list object (using `list.copy()`) when creating anew path object with a modified tail. This slightly speeds up`with_name()` and `with_suffix()`
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

Assignees

No one assigned

Labels

performancePerformance or resource usagetopic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@barneygale@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp