-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
Improve Windows performance of pathlib.Path.is_file
and friends
#101357
Comments
It would be a shame to lose the generic implementations in pathlib -- they'll be useful in a future |
@barneygale, wouldn't this enhancement entail |
We support subclassing as of #31691, which means that a user on Windows can do this: class MyClass(pathlib.Path):
pass
P = MyClass() ... and expect that Hence I'm hesistant to add things to |
The following `pathlib.Path` methods now directly call functions in `os.path`: - `samefile()` - `exists()` - `is_dir()` - `is_file()` - `is_symlink()` The original generic implementations of these methods are preserved in a new, internal `_PathWithStat` class. In future this may form the basis of a public `AbstractPath` class. The generic implementation of `is_mount()`, which was removed in 29650fea, is also restored to this class.
The following `pathlib.Path` methods now directly call functions in `os.path`: - `samefile()` - `exists()` - `is_dir()` - `is_file()` - `is_symlink()` In conjunction with python#101324, this improves performance of these methods by using making fewer system calls than `stat()` The original generic implementations of these methods are preserved in a new, internal `_PathWithStat` class. In future this may form the basis of a public `AbstractPath` class. The generic implementation of `is_mount()`, which was removed in 29650fea, is also restored to this class.
We can do like what you implemented for |
👍 that sounds good to me! Just as long as we adjust the |
Should This should be the complete set of ignored Windows error codes: // ENOENT
ERROR_FILE_NOT_FOUND
ERROR_PATH_NOT_FOUND
ERROR_INVALID_DRIVE
ERROR_NO_MORE_FILES
ERROR_BAD_NETPATH
ERROR_BAD_NET_NAME
ERROR_BAD_PATHNAME
ERROR_FILENAME_EXCED_RANGE
// ENOTDIR
ERROR_DIRECTORY
// EBADF
ERROR_INVALID_HANDLE
ERROR_INVALID_TARGET_HANDLE
ERROR_DIRECT_ACCESS_HANDLE
// ELOOP
ERROR_CANT_RESOLVE_FILENAME
// others
ERROR_NOT_READY
ERROR_INVALID_NAME |
I wouldn't mind if the |
Oh, but we'd need to add optional |
Or switch function called in the pathlib methods based on that parameter. In newer versions of Windows, |
…`is_*()` Suppress all `OSError` exceptions from `pathlib.Path.exists()` and `is_*()` rather than a selection of more common errors as we do presently. Also adjust the implementations to call `os.path.exists()` etc, which are much faster on Windows thanks to pythonGH-101196.
PR: #118243 |
Apologize for my confusion, it has been a while since I followed this ticket. I was wondering if someone could clarify a little bit about the situation. From what I can see, the closing commit/PR only seems to change behaviors about @zooba's comment seems to imply that the improvement was already made at other places, but needing "newer version of Windows". In other words, if I upgraded to 3.14 in future, but have to use "older" version of Windows (for example. Win10), would I still get any notifiable performance improvement on Thanks in advance! |
The change of Lines 505 to 549 in fbe6a09
|
Thank you, now I understand. |
…`is_*()` (python#118243) Suppress all `OSError` exceptions from `pathlib.Path.exists()` and `is_*()` rather than a selection of more common errors as we do presently. Also adjust the implementations to call `os.path.exists()` etc, which are much faster on Windows thanks to pythonGH-101196.
Feature or enhancement
We could implement / reuse the same fast paths that we did for
os.path.*
in #101324 forpathlib.Path.*
. It will require a little more work, since thepathlib.Path
API can returnOSError
under certain circumstances, whereasos.path
would returnFalse
in those cases.Pitch
We saw a 12-25% speedup doing this for
os.path
. It would be unfortunate if people chose the lower-level API for performance reasons becausepathlib.Path
didn't match it in performance.Linked PRs
os.path.exists()
etc from pathlib #101361OSError
frompathlib.Path.exists()
andis_*()
#118243The text was updated successfully, but these errors were encountered: