Uh oh!
There was an error while loading. Please reload this page.
gh-117349: Micro-optimize a few os.path functions - #117350
Conversation
nineteendo
commented
Mar 29, 2024
I believe that's everything. If you would like these changes to be split up in multiple pull requests let me know. |
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood
left a comment
There was a problem hiding this comment.
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 |
Uh oh!
There was an error while loading. Please reload this page.
nineteendo
commented
Mar 29, 2024
Does that include unnesting? |
nineteendo
commented
Apr 1, 2024
Is there anything you still expect from me? Or can this finally be merged? I've listened to basically all the feedback. |
nineteendo
commented
Apr 1, 2024
The speed improvements seem way less impressive now. ;( |
nineteendo
commented
Apr 1, 2024
Are you happy now? |
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood
commented
Apr 2, 2024
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: |
nineteendo
commented
Apr 2, 2024
You don't have a usb stick "2GB_001" plugged in, so the function will return |
AlexWaygood
commented
Apr 2, 2024
heh, that makes sense |
nineteendo
commented
Apr 2, 2024
I've updated the benchmarks. Sadly, the only noticeable speedup for regular users is calling |
AlexWaygood
commented
Apr 2, 2024
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. |
nineteendo
commented
Apr 2, 2024
Can this be merged, or are we still waiting on something? |
AlexWaygood
commented
Apr 2, 2024
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. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
… into speedup-os.path
os.path functionsAlexWaygood
commented
Apr 2, 2024
Thanks @nineteendo |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
erlend-aasland
commented
Apr 3, 2024
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. |
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood
commented
Apr 3, 2024
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. |
Benchmarks
ntpath.py
script
posixpath.py
script
os.path#117349