Skip to content

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

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:posixpath-ismount-optimize2
Apr 17, 2024
Merged

serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:posixpath-ismount-optimize2

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

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

It is now 2-3 times faster if the user has permissions.
Comment thread Lib/posixpath.py
Comment thread Lib/posixpath.py Outdated
@nineteendo

nineteendo commented Apr 3, 2024 •

Copy link
Copy Markdown
Contributor

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

Comment thread Lib/posixpath.py
@nineteendo

Copy link
Copy Markdown
Contributor

@erlend-aasland, could you review this?

@erlend-aasland

Copy link
Copy Markdown
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.
bandrel added a commit to trustedsec/hate_crack that referenced this pull request Oct 2, 2026
…e stability)

readline completer delimiters on macOS libedit must NOT include \n (newline).
When newline is a delimiter and the prompt contains embedded newlines (which
26+ input locations in hate_crack do), libedit's cursor position tracking
becomes unstable during completion, causing backspace to be ignored or behave
unexpectedly.

Removing \n from readline.set_completer_delims() in both attacks.py and
main.py restores stable backspace behavior while maintaining tab completion.

Fixes: Random inability to backspace in menu prompts
Ref: python/cpython#117447

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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