GH-114847: Speed up posixpath.realpath()#114848
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. |
gpshead
left a comment
There was a problem hiding this comment.
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. |
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