-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-100562: improve performance of pathlib.Path.absolute()
#100563
gh-100562: improve performance of pathlib.Path.absolute()
#100563
Conversation
Increase performance of the `absolute()` method by calling `os.getcwd()` directly, rather than using the `Path.cwd()` class method. This avoids constructing an extra `Path` object (and the parsing/normalization that comes with it). Decrease performance of the `cwd()` class method by calling the `Path.absolute()` method, rather than using `os.getcwd()` directly. This involves constructing an extra `Path` object. We do this to maintain a longstanding pattern where `os` functions are called from only one place, which allows them to be more readily replaced by users. As `cwd()` is generally called at most once within user programs, it's a good bargain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me. I agree that it's much more important to optimise Path.absolute()
than Path.cwd()
, and I can reproduce the huge speedup.
Is the plan still to hold off merging this for now until #100563 (comment) is resolved, or can this be merged at any time?
Misc/NEWS.d/next/Library/2022-12-28-00-28-43.gh-issue-100562.Hic0Z0.rst
Outdated
Show resolved
Hide resolved
Thanks for the review!
I think this can be merged any time. The backport for the fix for Eryk's issue will be slightly more complicated, but I will cope :D |
…ic0Z0.rst Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
I think all the tests are failing because Guido just broke the But I'll re-run the tests here as soon as the fix in #100778 is merged (just to be on the safe side), then I'll merge! |
Status check is done, and it's a success ✅. |
|
Looks like a fluke to me, I can't see how this change would mean that |
Increase performance of the
absolute()
method by callingos.getcwd()
directly, rather than using thePath.cwd()
class method. This avoids constructing an extraPath
object (and the parsing/normalization that comes with it).Decrease performance of the
cwd()
class method by calling thePath.absolute()
method, rather than usingos.getcwd()
directly. This involves constructing an extraPath
object. We do this to maintain a longstanding pattern whereos
functions are called from only one place, which allows them to be more readily replaced by users. Ascwd()
is generally called at most once within user programs, it's a good bargain.Automerge-Triggered-By: GH:AlexWaygood