Skip to content
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

Speed up posixpath.realpath() #114847

Closed
barneygale opened this issue Feb 1, 2024 · 2 comments
Closed

Speed up posixpath.realpath() #114847

barneygale opened this issue Feb 1, 2024 · 2 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@barneygale
Copy link
Contributor

barneygale commented Feb 1, 2024

Some optimizations to posixpath.realpath() are possible - see attached PR.

Linked PRs

@barneygale barneygale added performance Performance or resource usage stdlib Python modules in the Lib dir labels Feb 1, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Feb 1, 2024
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()`
barneygale added a commit to barneygale/cpython that referenced this issue Feb 1, 2024
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()`
barneygale added a commit to barneygale/cpython that referenced this issue Mar 31, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Apr 1, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Apr 2, 2024
…achable)'

On Linux >= 2.6.36 with glibc < 2.27, `getcwd()` can return a relative
pathname starting with '(unreachable)'. We detect this and fail with
ENOENT, matching new glibc behaviour.
barneygale added a commit to barneygale/cpython that referenced this issue Apr 2, 2024
barneygale added a commit that referenced this issue Apr 3, 2024
…e)' (#117481)

On Linux >= 2.6.36 with glibc < 2.27, `getcwd()` can return a relative
pathname starting with '(unreachable)'. We detect this and fail with
ENOENT, matching new glibc behaviour.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
barneygale added a commit to barneygale/cpython that referenced this issue Apr 3, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Apr 4, 2024
@encukou

This comment was marked as off-topic.

barneygale added a commit to barneygale/cpython that referenced this issue Apr 4, 2024
barneygale added a commit that referenced this issue Apr 5, 2024
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>
@encukou
Copy link
Member

encukou commented Apr 8, 2024

Thank you!

@encukou encukou closed this as completed Apr 8, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…achable)' (python#117481)

On Linux >= 2.6.36 with glibc < 2.27, `getcwd()` can return a relative
pathname starting with '(unreachable)'. We detect this and fail with
ENOENT, matching new glibc behaviour.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants