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-103548: Improve performance ofpathlib.Path.[is_]absolute()#103549

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
barneygale merged 10 commits intopython:mainfrombarneygale:gh-103548-absolute-perf
May 6, 2023

Conversation

@barneygale
Copy link
Contributor

@barneygalebarneygale commentedApr 14, 2023
edited
Loading

Pass theunnormalized path toos.path.isabs():

$ ./python -m timeit -s 'from pathlib import Path; p = Path("/etc")' 'p.is_absolute()'1000000 loops, best of 5: 375 nsec per loop  # before1000000 loops, best of 5: 240 nsec per loop  # after

When making an empty path absolute, avoid callingos.path.join(), and prevent pathlib from later re-normalizing the result ofos.getcwd() by storing it aspath._str:

$ ./python -m timeit -s 'from pathlib import Path' 'str(Path.cwd())'50000 loops, best of 5: 9.1 usec per loop    # before100000 loops, best of 5: 3.73 usec per loop  # after

Pass the *unnormalized* path to `os.path.isabs()`.When making an empty path absolute, avoid calling `os.path.join()`, andprevent pathlib from later re-normalizing the result of `os.getcwd()` bystoring it as `path._str`.
@AlexWaygoodAlexWaygood added type-featureA feature request or enhancement performancePerformance or resource usage 3.12only security fixes labelsMay 6, 2023
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.

LGTM!

@barneygalebarneygaleenabled auto-merge (squash)May 6, 2023 17:37
@barneygalebarneygale merged commitde7f694 intopython:mainMay 6, 2023
jbower-fb pushed a commit to jbower-fb/cpython that referenced this pull requestMay 8, 2023
pythonGH-103549)Improve performance of `pathlib.Path.absolute()` and `cwd()` by joining paths only when necessary. Also improveperformance of `PurePath.is_absolute()` on Posix by skipping path parsing and normalization.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eryksuneryksuneryksun left review comments

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

Assignees

No one assigned

Labels

3.12only security fixesperformancePerformance or resource usagetopic-pathlibtype-featureA feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@barneygale@eryksun@AlexWaygood@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp