Title: bpo-37935: Improve performance of pathlib.scandir() by ShaiAvr · Pull Request #15331 · python/cpython · GitHub
Open Graph Title: bpo-37935: Improve performance of pathlib.scandir() by ShaiAvr · Pull Request #15331 · python/cpython
X Title: bpo-37935: Improve performance of pathlib.scandir() by ShaiAvr · Pull Request #15331 · python/cpython
Description: I recently have taken a look in the source code of the pathlib module, and I saw something weird there: when the module used the scandir function, it first converted its iterator into a list and then used it in a for loop. The list wasn't used anywhere else, so I think the conversion to list is just a waste of performance. In addition, I noticed that the scandir iterator is never closed (it's not used in a with statement and its close method isn't called). I know that the iterator is closed automatically when it's garbaged collected, but according to the docs, it's advisable to close it explicitly. So, I changed the code so that, scandir is used in a with statement and its iterator is used directly in the for loop instead of being converted to list first, which should enhance the performance. https://bugs.python.org/issue37935
Open Graph Description: I recently have taken a look in the source code of the pathlib module, and I saw something weird there: when the module used the scandir function, it first converted its iterator into a list and th...
X Description: I recently have taken a look in the source code of the pathlib module, and I saw something weird there: when the module used the scandir function, it first converted its iterator into a list and th...
Opengraph URL: https://github.com/python/cpython/pull/15331
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ec6d84d9-a20b-7247-6908-2742f3bbc027 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 811C:3A60C6:6C8CB8:9425AE:6A55A296 |
| html-safe-nonce | 7a32083e06eacd5514c43b42c46a2e8b8abd37b5c34973e3ca236fbd2acb7f2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTFDOjNBNjBDNjo2QzhDQjg6OTQyNUFFOjZBNTVBMjk2IiwidmlzaXRvcl9pZCI6IjI5OTE5MDIxMDMxMDUyODI3MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5e16ec0c5f0ea1dcd9d46635ee80bd09f28fd2450fdf1578c3594170085621fa |
| hovercard-subject-tag | pull_request:308516871 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/15331/files |
| twitter:image | https://avatars.githubusercontent.com/u/35605235?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/35605235?s=400&v=4 |
| og:image:alt | I recently have taken a look in the source code of the pathlib module, and I saw something weird there: when the module used the scandir function, it first converted its iterator into a list and th... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 653fccf1e27344851c0d3de3fa6faa526197f072 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width