Skip to content

gh-117394: Speed up os.path.ismount() on Posix #117447

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 2, 2024

It is now 2-3 times faster if the user has permissions.

It is now 2-3 times faster if the user has permissions.
@nineteendo
Copy link
Contributor

nineteendo commented Apr 3, 2024

Benchmark:

# test.sh
echo "relative" && python -m timeit -s "import before.posixpath" "before.posixpath.ismount('.')" && python -m timeit -s "import after.posixpath" "after.posixpath.ismount('.')"
echo "absolute" && 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')"
echo "no permission" && python -m timeit -s "import before.posixpath" "before.posixpath.ismount('/Users/wannes/path-picker/permission-test/dirs/666')" && python -m timeit -s "import after.posixpath" "after.posixpath.ismount('/Users/wannes/path-picker/permission-test/dirs/666')"
relative
10000 loops, best of 5: 27.3 usec per loop # before
50000 loops, best of 5: 8.25 usec per loop # after
# -> 3.29x faster
absolute
20000 loops, best of 5: 19.7 usec per loop # before
50000 loops, best of 5: 8.21 usec per loop # after
# -> 2.40x faster
no permission
5000 loops, best of 5: 41.2 usec per loop # before
5000 loops, best of 5: 48.5 usec per loop # after
# -> 1.18x slower

@nineteendo
Copy link
Contributor

@erlend-aasland, could you review this?

@erlend-aasland
Copy link
Contributor

Looks good to me, but I'm not sure if it worth the added maintenance cost to optimise this. I mean, how often is the ismount API used? I'll leave it for Serhiy to decide.

@serhiy-storchaka serhiy-storchaka merged commit 4e502a4 into python:main Apr 17, 2024
@serhiy-storchaka serhiy-storchaka deleted the posixpath-ismount-optimize2 branch April 17, 2024 09:58
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
It is now 2-3 times faster if the user has permissions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants