-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Remove _get_[both]sep[s]()
calls in os.path
#117634
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
Comments
This is being worked on: |
OK, but calling a function will always have some overhead, we can never fully eliminate that (unless we add macro's to python). -seps = _get_bothseps(p)
+seps = b'\\/' if isinstance(p, bytes) else '\\/' |
Why do you think that the isinstance call faster than the _get_bothseps call? Removing a redundant call is another matter. |
@terryjreedy, |
In my benchmarks, the new code is 4-12% faster: #117635 (comment). If you want benchmarks for longer input, let me know. Also, Lines 377 to 378 in e338e1a
Doing that makes it 61% faster for long user names (>100 characters). |
I'm not sure the performance win outweights the increase in code duplication. |
Do I need to make a separate issue for |
As I've said earlier, micro-optimisations are generally hard to get support for; we mostly prefer code clarity, readability and maintainability over performance. I would instead encourage you to direct your enthusiasm towards the existing issues in the bug-tracker. There's close to 7000 issues in the tracker. What we really need help with, is triaging this heap of issues, fixing those who can be fixed, closing those who are invalid, etc. I think you could be of real help (and you would experience more support from the core team) if you directed your skills towards the bug-tracker. |
I've made a separate issue for |
That's seems a fair point. I suggest to close this issue, though; IMO the performance gains do not outweigh the added code duplication nor the churn.
That's great; thanks for helping reducing our backlog! |
Feature or enhancement
Proposal:
Python function calls are always expensive. We can replace all
_get_sep()
&_get_bothseps()
calls inos.path
with ternary operators, merging with existingisinstance()
checks where applicable. e.g:Also, in
posixpath.expanduser()
we can replaceroot
with the already assignedsep
from earlier:Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
os.path
#117610Linked PRs
_get_[both]sep[s]()
calls inos.path
#117635The text was updated successfully, but these errors were encountered: