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

Optimize pathlib.Path.absolute() #112727

Closed
barneygale opened this issue Dec 4, 2023 · 0 comments
Closed

Optimize pathlib.Path.absolute() #112727

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

Comments

@barneygale
Copy link
Contributor

barneygale commented Dec 4, 2023

The implementation of pathlib.Path.absolute() can call with_segments() with multiple arguments; the resulting path object will be internally unjoined and unparsed, making str(path.absolute()) slow, amongst other things.

absolute() already has most of the information it needs to produce paths that are pre-joined, and either pre-parsed (if the input has tail segments) or pre-stringified (otherwise). This could provide a tasty speedup.

Linked PRs

@barneygale barneygale added performance Performance or resource usage topic-pathlib labels Dec 4, 2023
barneygale added a commit to barneygale/cpython that referenced this issue Dec 4, 2023
Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, rather
than passing multiple arguments to `with_segments()`
barneygale added a commit that referenced this issue Dec 4, 2023
Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, rather
than passing multiple arguments to `with_segments()`

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Use `_from_parsed_parts()` to create a pre-joined/pre-parsed path, rather
than passing multiple arguments to `with_segments()`

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
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