-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
GH-114847: Speed up posixpath.realpath()
#114848
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
Apply the following optimizations to `posixpath.realpath()`: - Remove use of recursion - Directly construct child paths rather than using `join()` - Use `os.getcwd[b]()` rather than `abspath()` - Use `startswith(sep)` rather than `isabs()`
I've added a few wordy comments because:
Hopefully it's a bit easier for the next person to grok with the comments in place. |
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.
I like that this gets rid of recursion.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Given that symlinks are rare, perhaps I've actually slowed things down by checking in |
The introduction of a Given a directory and a link to it:
with Python 3.12 I get:
With this PR:
The previous behaviour matches coreutils:
|
Thanks. I see the other use of
Guess that's one bug we need to let live. |
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, thank you!
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Thank you for the reviews! |
(For posterity:) I opened an issue about this: #117546 |
Apply the following optimizations to `posixpath.realpath()`: - Remove use of recursion - Construct child paths directly rather than using `join()` - Use `os.getcwd[b]()` rather than `abspath()` - Use `startswith(sep)` rather than `isabs()` - Use slicing rather than `split()` Co-authored-by: Petr Viktorin <encukou@gmail.com>
Apply the following optimizations to
posixpath.realpath()
:join()
os.getcwd[b]()
rather thanabspath()
startswith(sep)
rather thanisabs()
split()
posixpath.realpath()
#114847