Skip to content

gh-117394: Reduce syscalls for posixpath.ismount - #117395

Closed
nineteendo wants to merge 5 commits into
python:mainfrom
nineteendo:speedup-posixpath.ismount
Closed

gh-117394: Reduce syscalls for posixpath.ismount#117395
nineteendo wants to merge 5 commits into
python:mainfrom
nineteendo:speedup-posixpath.ismount

Conversation

@nineteendo

@nineteendonineteendo commented Mar 30, 2024

Copy link
Copy Markdown
Contributor

Benchmark:

python -m timeit -s "import before.posixpath" "before.posixpath.ismount('/Volumes/2GB_001')" && python -m timeit -s "import after.posixpath" "after.posixpath.ismount('/Volumes/2GB_001')"
10000 loops, best of 5: 21.3 usec per loop # before
50000 loops, best of 5: 8.5 usec per loop # after
# -> 2.51x faster

…e-117394.qCepkD.rst
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@nineteendo
nineteendo marked this pull request as ready for review March 30, 2024 19:42
@barneygale

barneygale commented Mar 30, 2024

Copy link
Copy Markdown
Contributor

What happens if /mnt/storage is a mount point, /mnt/storage/link is a symlink to /mnt, and you call ismount('/mnt/storage/link/storage')? I think the new implementation gives a different answer.

@nineteendonineteendo mentioned this pull request Mar 30, 2024
16 tasks
@nineteendo

Copy link
Copy Markdown
ContributorAuthor

Good thinking! The old implementation returns True in that case, the new implementation False.
But that can easily fixed by replacing os.lstat() with os.stat().

@barneygale

Copy link
Copy Markdown
Contributor

Serhiy suggested a similar patch previously: #46718 (comment)

Compared to Serhiy's patch, this PR adds a abspath() call, which internally calls normpath(). I think that eliminates the remaining edge cases (e.g. trailing slashes, dots in paths, etc).

@nineteendo

Copy link
Copy Markdown
ContributorAuthor

What's going on here? https://github.com/python/cpython/actions/runs/8504085005/job/23290509561?pr=117395#step:16:481
I don't know the value of ABSTFN.

@nineteendo

nineteendo commented Apr 1, 2024

Copy link
Copy Markdown
ContributorAuthor

Oh, I know why. This test needs to be updated: it monkey patches os.lstat instead of os.stat.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Sorry, but abspath() is unsuitable for this. See details in #117394 (comment).

@nineteendo
nineteendo deleted the speedup-posixpath.ismount branch April 3, 2024 14:25
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@nineteendo@barneygale@serhiy-storchaka@AlexWaygood