Title: Add fast path to os.[l]stat() that returns incomplete information · Issue #99726 · python/cpython · GitHub
Open Graph Title: Add fast path to os.[l]stat() that returns incomplete information · Issue #99726 · python/cpython
X Title: Add fast path to os.[l]stat() that returns incomplete information · Issue #99726 · python/cpython
Description: A future update to Windows is bringing a new filesystem API for getting stat(-like) information more efficiently from a filename. Currently, we have to open the file, which is quite a slow operation. Being able to simply request metadata...
Open Graph Description: A future update to Windows is bringing a new filesystem API for getting stat(-like) information more efficiently from a filename. Currently, we have to open the file, which is quite a slow operatio...
X Description: A future update to Windows is bringing a new filesystem API for getting stat(-like) information more efficiently from a filename. Currently, we have to open the file, which is quite a slow operatio...
Opengraph URL: https://github.com/python/cpython/issues/99726
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add fast path to os.[l]stat() that returns incomplete information","articleBody":"A future update to Windows is bringing a new filesystem API for getting stat(-like) information more efficiently from a filename. Currently, we have to open the file, which is quite a slow operation. Being able to simply request metadata based on the path is a real improvement. My testing shows `os.stat()` and `os.lstat()` (in the case where no traversal is needed) taking less than 1/4 of their current time when using the new API. I'll link the change in a PR below.\r\n\r\n_However_, the new API does not include the volume serial number, which is how we fill in the `st_dev` field. Adding an additional call to get the VSN takes all the time we were taking before, so there's no performance benefit.[^1]\r\n\r\nSo I'd like to propose adding a `fast=False` argument to `os.stat` and `os.lstat`. When left as `False`, you get the current behaviour. If you pass `True`, we only guarantee a smaller set of data, and warn that other fields may be absent on some platforms.\r\n\r\nLooking through the fields, I have proposed that the file type bits of `st_mode` (not permissions), the `st_size` and `st_mtime[_ns]` fields are the only ones that are important to guarantee.[^2] All the rest can stay as they are, but we then have the option to drop them from the fast path in the future.[^3] It's no accident that these are the APIs we already offer as other `os.path` functions (apart from `samestat`, which will have to stay on the slow path and probably needs an even slower check in order to be x-plat reliable...)\r\n\r\nI'm not sure who cares most about this, so I'm going to leave this open for a while.\r\n\r\n[^1]: There is still discussion about changing this API before it releases. If that happens, the rest of this proposal is moot, unless we like the idea anyway.\r\n\r\n[^2]: On Windows, we can further guarantee `st_file_attributes` and `st_reparse_tag`, as these are the raw values used to calculate the file type bits of `st_mode`.\r\n\r\n[^3]: stat is already very fast on POSIX-ish filesystems, so it's unlikely to be an issue there, but if we wanted to specialise for network FS or similar then we'd be able to.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-99727\n* gh-99755\n* gh-102149\n* gh-102976\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/zooba","@type":"Person","name":"zooba"},"datePublished":"2022-11-23T15:14:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/99726/cpython/issues/99726"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fcdb7816-1e94-cbe9-0296-89767cf177ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9034:25FEA8:8AC641:C28D99:696A210F |
| html-safe-nonce | e5651ee65ba1a5195ec4a0d476978ef930ff1349bac32dd20977449851bb7bb0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDM0OjI1RkVBODo4QUM2NDE6QzI4RDk5OjY5NkEyMTBGIiwidmlzaXRvcl9pZCI6IjY1MjgxOTE3MjU3OTA5NjE5MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3caac9736d95cc23adb902d2030919d6a9ebfda2e6ada4d15bb1948002386fe8 |
| hovercard-subject-tag | issue:1461942094 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/99726/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f1ed398d2c846ee4084a97b0729fbcd7bdd0f56bc5133b51a5d7352d7f4aa78/python/cpython/issues/99726 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f1ed398d2c846ee4084a97b0729fbcd7bdd0f56bc5133b51a5d7352d7f4aa78/python/cpython/issues/99726 |
| og:image:alt | A future update to Windows is bringing a new filesystem API for getting stat(-like) information more efficiently from a filename. Currently, we have to open the file, which is quite a slow operatio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zooba |
| hostname | github.com |
| expected-hostname | github.com |
| None | 014f3d193f36b7d393f88ca22d06fbacd370800b40a547c1ea67291e02dc8ea3 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d515f6f09fa57a93bf90355cb894eb84ca4f458f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width