-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-117349: Micro-optimize a few os.path
functions
#117350
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
Conversation
I believe that's everything. If you would like these changes to be split up in multiple pull requests let me know. |
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.
As @sobolevn says, it's very difficult to see here which changes are actually related to performance improvements, and which are simply cosmetic changes that have no impact on how the code works. Our general policy is not to accept cosmetic changes, but even if we decided that we wanted to make an exception here, any such stylistic/formatting improvements would have to go into their own PR, so that the git history clearly showed which changes were performance-related and which were cosmetic.
Please revert all changes that do not actually have any impact on performance.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Does that include unnesting? |
Is there anything you still expect from me? Or can this finally be merged? I've listened to basically all the feedback. |
The speed improvements seem way less impressive now. ;( |
Are you happy now? |
I re-ran your benchmarks locally. With the latest version of your PR, I'm getting a reasonable slowdown on On
With your PR branch:
|
You don't have a usb stick "2GB_001" plugged in, so the function will return |
heh, that makes sense |
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.
LGTM
I've updated the benchmarks. Sadly, the only noticeable speedup for regular users is calling |
Don't be too disheartened. As a result of your efforts here, a conversation has been started about possible ways of optimising Optimising the stdlib is hard! I tried out many things that ultimately didn't work when I was working on #74690. And there were several things that did work, but which I never created PRs for, as they would have made the code too ugly or too fragile. My advice for the future, however, would definitely be to work on small, focused PRs that have isolated, easily measurable changes. PRs like that are much easier for us to review, and you should find the contributing experience less frustrating as a result. |
Can this be merged, or are we still waiting on something? |
It can be merged, I just wanted to wait a little bit longer to give the other reviewers time to chime in on the final version of the PR, if they wanted to. I'll merge tomorrow or the day after if there are no further objections from anybody. |
Co-authored-by: Pieter Eendebak <[email protected]>
… into speedup-os.path
os.path
functions
Thanks @nineteendo |
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.
LGTM.
Both cases were significantly improved by #117466:
I think we should be careful about micro-optimising Python code, like this PR. Instead, it would be better to keep the code as idiomatic as possible, and instead optimise the Python interpreter for the idiomatic cases. |
I agree that we should neither accept micro-optimisations that make code significantly less idiomatic, nor changes that are purely cosmetic and have no impact on performance. I accepted the PR nonetheless because in the final iteration of the PR, all changes seemed to me to be small, localised changes that, as well as providing small speedups, mostly made the code more idiomatic, and in all cases (in my opinion) did not cause a significant deterioration in style. |
I didn't expect the second case to be sped up as it was a sequence, so I asked for clarification: faster-cpython/ideas#671 (comment), but didn't get a response. This speedup must have been added afterwards, which I missed. |
) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Barney Gale <[email protected]> Co-authored-by: Pieter Eendebak <[email protected]>
Benchmarks
ntpath.py
script
posixpath.py
script
os.path
#117349